PowerShell 学习入门-1

PowerShell 学习 入门

#创建 PowerShell . ps1 文件 

#获取当前执行 完全路径:

#working directory path

$workingDir = Split-Path -Parent $MyInvocation.MyCommand.Definition

#创建新的文件夹,参数:文件路径文件名 e. C:\temp

#function : create new folder  if not exist.
function Createfolder([string] $pathName = $(throw "pathName is required !"))
{
    if(Test-Path -Path $pathName)
    {
        #folder is already there, do nothing.
    }
    else
    {
        New-Item -Path $pathName -ItemType directory
    }
}

#检查是否为空文件夹

# Check if a given folder is empty or not.
function IsFolderEmpty([string]$pathName = $(throw "pathName is required"))
{
    return ((Get-ChildItem $pathName).Count -eq 0)
}

#复制文件夹 及文件

#copy all files to working folder
function CopyFiles(
    [string] $sourcePath = $(throw "sourcePath is required !"),
    [string] $targetPath = $(throw "targetPath is required !"))
{
    if (IsFolderEmpty $sourcePath) {
        #folder is empty.
        Write-Output "Nothing to copy."
    } else {
        $i = 0
        Copy-Item -Path $sourcePath -Destination $targetPath -Recurse -Force -PassThru | 
            ForEach-Object { $i = $i +1; Write-Output "  $i  Copied: $_";} 
    }
}

#今天到这儿了,只是试一下效果而已

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值