Home > front end >  Compress multiple directories but exclude directory - Python zipfile(or anything native to Windows 2
Compress multiple directories but exclude directory - Python zipfile(or anything native to Windows 2

Time:05-09

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.

CodePudding user response:

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

  • Related