我正在尝试使用 PowerShell 进行压缩,但它并不排除 .zip 文件中列出的文件excluded_paths
。我想特别排除所有__pycache__
可以嵌套在 python 代码库的不同级别中的文件夹。目前,所有内容都被压缩,包括应该排除的文件和文件夹。
$excluded_paths = @(
"${parent_folder}/.vscode/*",
"${parent_folder}/.git/*",
"${parent_folder}/temp/*",
"${parent_folder}/resources/documentation/*",
"${parent_folder}/**/useful/*",
"${parent_folder}/scripts/*",
"${parent_folder}/*.template.*",
"${parent_folder}/*TODO.*",
"${parent_folder}/$(Get-Item -Path $MyInvocation.MyCommand.Path).Name"
)
$exclude_pycache = Get-ChildItem -Path $parent_folder -Recurse -Directory -Filter "__pycache__" | ForEach-Object { $_.FullName }
$excluded_paths += $exclude_pycache
Pause
$winrar_path = "C:\Program Files\WinRAR\WinRAR.exe"
#$exclusion_switches = $excluded_paths | ForEach-Object { "-x'$_'" }
#& $winrar_path a -r -ep1 $exclusion_switches "$output_zip" "${parent_folder}\*"
$exclusion_string = $excluded_paths -join ' '
& $winrar_path a -r -ep1 "-x$exclusion_string" "$output_zip" "${parent_folder}\*"
我试过这个:
$exclusion_switches = $excluded_paths | ForEach-Object { "-x'$_'" }
& $winrar_path a -r -ep1 $exclusion_switches "$output_zip" "${parent_folder}\*"
并尝试了这个:
$exclusion_string = $excluded_paths -join ' '
& $winrar_path a -r -ep1 "-x$exclusion_string" "$output_zip" "${parent_folder}\*"
即使是一个简单的例子:
& $winrar_path a -r -x__pycache__ "$output_zip" "${parent_folder}\*"
不起作用。它会压缩,但不会排除所有__pycache__
文件夹。
好的,我试过了
& $winrar_path a -r "-x*__pycache__*" "$output_zip" "${parent_folder}\*"
这有效,但WinRAR 文档没有提到引用它。
我究竟做错了什么?