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: $_";}
}
}
#今天到这儿了,只是试一下效果而已