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

前端 未结 10 921
旧时难觅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:26

    I was looking for a way to copy files modified after a certain date/timestamp so as to archive them. This way I could save off exactly what files I worked on (assuming I know when I started). (Yes, I know this is what SCM is for, but there are times when I just want to snapshot my work without checking it in.)

    Using landyman's tip, and stuff I found elsewhere, I found that this worked:

    $source = 'c:\tmp\foo'
    $dest = 'c:\temp\foo'
    $exclude = @('*.pdb', '*.config')
    Get-ChildItem $source -Recurse -Exclude $exclude |  
        where-object {$_.lastwritetime -gt "8/24/2011 10:26 pm"} | 
        Copy-Item -Destination {Join-Path $dest $_.FullName.Substring($source.length)}
    

提交回复
热议问题