【发布时间】:2013-11-19 12:00:53
【问题描述】:
我正在使用 Powershell v 2.0。并将文件和目录从一个位置复制到另一个位置。我正在使用 string[] 来过滤掉文件类型,并且还需要过滤掉被复制的目录。文件被正确过滤掉了,但是,我试图过滤的目录obj 一直被复制。
$exclude = @('*.cs', '*.csproj', '*.pdb', 'obj')
$items = Get-ChildItem $parentPath -Recurse -Exclude $exclude
foreach($item in $items)
{
$target = Join-Path $destinationPath $item.FullName.Substring($parentPath.length)
if( -not( $item.PSIsContainer -and (Test-Path($target))))
{
Copy-Item -Path $item.FullName -Destination $target
}
}
我尝试了各种过滤方法,\obj 或 *obj* 或 \obj\ 但似乎没有任何效果。
感谢您的帮助。
【问题讨论】: