简体   繁体   English

使用Powershell提取zip文件时,最后一个zip文件失败。

[英]Extracting zip files with Powershell failing on last zip file.

I'm trying to unzip multiple zip files within a directory using a Powershell script. 我正在尝试使用Powershell脚本解压缩目录中的多个zip文件。 Everything goes well, except it always fails during the last zip file in the directory. 一切正常,除了在目录中的最后一个zip文件期间始终失败。 The zip file isn't corrupt - I can manually unzip it just fine. 压缩文件没有损坏-我可以手动将其解压缩。 It starts extracting the contents (I can see it being populated in Windows Explorer), but then towards the end it fails, removes the extracted contents from that zip file from Windows Explorer, and throws out the following error: 它开始提取内容(我可以看到它正在Windows资源管理器中填充),但是到最后它失败了,从Windows资源管理器中从该zip文件中删除提取的内容,并抛出以下错误:

Exception calling "ExtractToFile" with "3" argument(s). "Could not find a part of the path '<path-to-a-file-within-the-zip-archive>. 

I'm unsure of why this is happening when all of the other zips unzip just fine. 我不确定为什么当所有其他拉链解压缩时会发生这种情况。 I've also found out that this does not happen whenever I extract the files to the same directory as the Powershell script that is executing this code. 我还发现,只要将文件提取到与执行此代码的Powershell脚本相同的目录中,就不会发生这种情况。

Here is my code that unzips the files: 这是我解压缩文件的代码:

 Get-ChildItem .\ZipFilesDirectory-Filter *.zip | Expand-Archive -DestinationPath .\ExtractedZipFolders -Force

It turns out there was a file in my zip archive that resulted in a "Path too long" issue when extracting to the desired directory. 事实证明,我的zip存档中有一个文件,提取到所需目录时导致“路径太长”问题。 As a workaround, I extracted the archive to my C drive (C:/), then moved it to the proper directory. 解决方法是,将存档解压缩到C驱动器(C:/),然后将其移至正确的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM