压缩多个目录但排除目录 - Python zipfile(或 Windows 2012+ 原生的任何内容)

Compress multiple directories but exclude directory - Python zipfile(or anything native to Windows 2012+)

我正在寻找一种方法来压缩多个目录,同时在 Windows 的多个版本中排除特定目录。不幸的是,tar 仅在 Win 10+ 上默认可用,并且 Compress-Archive 似乎对我不起作用,因为如果正在使用某个文件,它会失败。

Python 似乎是我能想到的唯一选择,但不确定是否可行。

我目前正在使用

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

是否可以排除特定的子目录?例如。 dir1/subD1

虽然 python 似乎是理想的选择,但如果这不可能,我会喜欢任何其他建议。需要使用 Windows 2012+ 或 Python.

所有版本的原生内容

谢谢。

尝试将 python 命令与 Get-ChildItem 配对。像这样:

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

或者使用 System.IO.Compression.GzipStream class (.NET 2.0) 进行更精细的处理。
看看This