Exclude list in PowerShell Copy-Item does not appear to be working

前端 未结 10 904
旧时难觅i
旧时难觅i 2020-12-02 11:40

I have the following snippet of PowerShell script:

$source = \'d:\\t1\\*\'
$dest = \'d:\\t2\'
$exclude = @(\'*.pdb\',\'*.config\')
Copy-Item $source $dest -R         


        
10条回答
  •  一向
    一向 (楼主)
    2020-12-02 12:38

    The exclude parameter won't work with dirs. A variant of Bo's script does the trick:

    $source = 'c:\tmp\foo'
    $dest = 'c:\temp\foo'
    $exclude = '\.bak'
    Get-ChildItem $source -Recurse  | where {$_.FullName -notmatch $exclude} | 
        Copy-Item -Destination {Join-Path $dest $_.FullName.Substring($source.length)}
    

提交回复
热议问题