How do I exclude a folder in compress-archive

前端 未结 2 1509
不知归路
不知归路 2021-02-19 06:37

Can I somehow exclude a folder when I compress an archive like this?

$compress = Compress-Archive $DestinationPath $DestinationPath\\ARCHIVE\\archiv-$DateTime.zi         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-19 06:58

    you can use -update option of Compress-Archive. Select your subdirs with Get-ChildItem and Where

    like it:

    $YourDirToCompress="c:\temp"
    $ZipFileResult="C:\temp10\result.zip"
    $DirToExclude=@("test", "test1", "test2")
    
    Get-ChildItem $YourDirToCompress -Directory  | 
               where { $_.Name -notin $DirToExclude} | 
                  Compress-Archive -DestinationPath $ZipFileResult -Update
    

提交回复
热议问题