0

I'm looking to find a way to compress multiple directories while excluding a certain directory on several versions of Windows. Unfortunately tar is only available by default on Win 10+ and Compress-Archive doesn't seem to work for me due to it failing if a certain file is in use.

Python seems like the only option I can think of but not sure if it's possible yet.

I'm currently using

python3 -m zipfile -c zipName.zip dir1 dir2 dir3

Is it possible to exclude a specific subdirectory? eg. dir1/subD1

While python seems like the ideal choice, I'd love any other suggestions if this isn't possible. Need to use something native to all versions of Windows 2012+ OR Python.

Thanks.

Anthony
  • 79
  • 1
  • 1
  • 9

1 Answers1

1

Try pairing the python command with Get-ChildItem. something like this:

$fileInfo = Get-ChildItem -Path 'C:\Path\To\Some\Files\*.*' -Exclude '*Exclude*'
python3 -m zipfile -c zipName.zip $fileInfo.FullName

Or use the System.IO.Compression.GzipStream class (.NET 2.0) for something more elaborate.
Take a look at This

FranciscoNabas
  • 505
  • 3
  • 9
  • Thank you, this is the closest I've gotten but the only issue is, it doesn't keep the same directory structure, it just copies all the files into the same directory... Any idea if this is possible to get around? My workaround so far is to use Copy-Item to copy the entire directory over, then use Python to zip it... – Anthony May 08 '22 at 21:37