目標是使用PowerShell將文件夾和文件從路徑複製到另一個路徑。但是,我想排除某些文件和文件夾被複制。我可以將它們添加到排除列表使用PowerShell進行復制時排除多個文件夾
Get-ChildItem -Path $source -Recurse -Exclude "web.config","body.css","Thumbs.db"
爲了排除文件夾排除多個文件我加
$directory = @("Bin")
?{$_.fullname -notmatch $directory}
最終副本的腳本看起來像
Get-ChildItem -Path $source -Recurse -Exclude "Web.config","body.css","Thumbs.db" | ?{$_.fullname -notmatch $directory} | Copy-Item -Force -Destination {if ($_.GetType() -eq [System.IO.FileInfo]) {Join-Path $dest $_.FullName.Substring($source.length)} else {Join-Path $dest $_.Parent.FullName.Substring($source.length)}}
這似乎與單個文件夾一起工作,但是當我將多個文件夾添加到排除的目錄時,它似乎無法工作。可以做些什麼來排除多個文件夾?
。它loooks like you want to use'$ _。basename' instead ..'where {{_。basename -notin $ dir -and $ _。psiscontainer -eq $ true}' – Kiran