How do I exclude a folder in compress-archive

前端 未结 2 1519
不知归路
不知归路 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:46

    Get all the files you want to compress, excluding the files and folders you don't want compressed and then pass that to the cmdlet

    # target path
    $path = "C:\temp"
    # construct archive path
    $DateTime = (Get-Date -Format "yyyyMMddHHmmss")
    $destination = Join-Path $path "ARCHIVE\archive-$DateTime.zip"
    # exclusion rules. Can use wild cards (*)
    $exclude = @("_*.config","ARCHIVE","*.zip")
    # get files to compress using exclusion filer
    $files = Get-ChildItem -Path $path -Exclude $exclude
    # compress
    Compress-Archive -Path $files -DestinationPath $destination -CompressionLevel Fastest
    

提交回复
热议问题