简体   繁体   中英

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. Everything goes well, except it always fails during the last zip file in the directory. 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:

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.

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. As a workaround, I extracted the archive to my C drive (C:/), then moved it to the proper directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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