1

我编写了一个 PowerShell 命令来压缩文件夹及其子目录,同时从主目录中排除文件。

当我执行命令时,它确实创建了包含所有子目录的 zip 文件,但它似乎不明白子目录与主文件位于同一管道中。

├── _subfolder
|   └── file.json
├── file.js
└── file.html

因此,当我尝试在 Firefox 的调试器中打开 zip 文件时,我收到以下错误:

Loading locale file _subfolder/file.json: Error: Error while loading 'jar:file:///C:/Users/xxx/Desktop/folder/archive.zip!/_subfolder/file.json' (NS_ERROR_FILE_NOT_FOUND)

这是我当前的代码:

# Target Path
$path = "c:\users\xxx\desktop\folder-to-zip\"
# Archive Path
$destination = "C:\users\xxx\desktop\folder\archive.zip"
# Exclude some files in the main folder
$exclude = "file.js"
# Choose files to zip
$files = Get-ChildItem $path -Exclude $exclude
#Compressing archive
Compress-Archive -Update -Path $files -DestinationPath $destination -CompressionLevel Fastest

如何确保 zip 包含有关文件层次结构的一些信息?当我使用 WinRAR 手动压缩时,我没有收到任何错误。

4

0 回答 0