【发布时间】:2021-11-05 18:52:41
【问题描述】:
我有以下简单的 powershell 来将一个 zip 文件夹(包含其他文件夹和仅日志文件)提取到目标
$FolderPath = "C:\Temp\Whatever"
Expand-Archive -Path "$FolderPath\logs.zip" -DestinationPath "$FolderPath\logs"
不幸的是,这会返回一大堆错误,如下所示......
Remove-Item : Cannot find path 'C:\Temp\Whatever\logs\1_Selenium SEPA-Test\Attempt1\1_Start VM's\Release\1_Initialize Agent.log' because it does not exist.
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:410 char:46
+ ... $expandedItems | % { Remove-Item $_ -Force -Recurse }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Temp\Whateve...alize Agent.log:String) [Remove-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
Remove-Item : Cannot find path 'C:\Temp\Whatever\logs\1_Selenium SEPA-Test\Attempt1\1_Start VM's\Release\1_Initialize Job.log' because it does not exist.
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:410 char:46
+ ... $expandedItems | % { Remove-Item $_ -Force -Recurse }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Temp\Whateve...tialize Job.log:String) [Remove-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
还有很多类似的错误
我可以确认第一个错误C:\Temp\Whatever\logs\1_Selenium SEPA-Test\Attempt1\1_Start VM's\Release\1_Initialize Agent.log 中引用的文件确实存在于 zip 文件夹中的等效位置...
脚本结束后,我在指定目录中看到一个不完整的文件夹。
这是怎么回事?
谢谢,
【问题讨论】:
-
如果您只是将
-DestinationPath更改为不同的文件夹会怎样? -
不幸的是没有帮助
-
你能用7z e吗?有一个 powershell script 用于运行它。
-
可能是您的存档存在问题:github.com/PowerShell/Microsoft.PowerShell.Archive/issues/12 这个问题现在似乎已经修复,因此如果您运行的是旧版本,您可能需要更新 Powershell。
-
我使用的是 powershell 5.1。我已经设法使用 7z e 拼凑出一个解决方案
标签: powershell