How to exclude a folder in a compressed archive

Is there any way to exclude a folder when I compress such an archive?

$compress = Compress-Archive $DestinationPath $DestinationPath\ARCHIVE\archiv-$DateTime.zip -CompressionLevel Fastest 

Now it always saves the entire $destinationpath folder structure to the archive, but since the archive is in the same folder, it always loops on the new archive, making the archive double in size each time I run the command.

+5
source share
2 answers

you can use the -update option for Compress-Archive. Select Subdirs with Get-ChildItem and Where

like:

 $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 
+4
source

Get all the files you want to compress, except for the files and folders that you don't want to compress, and then pass them 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 
+3
source

Source: https://habr.com/ru/post/1261098/


All Articles