Extract ZIP file and then all sub-zip files

Below is a method I've used in the past for the same type of task that you describe which I pulled from one of my "bag of scripts". I used the free 7-Zip application for this task with 100% success.

Essentially this . . .

  • Uses the 7-Zip (7za) app to extract zip file(s) contents in one location to another
  • Then it does an xcopy of extracted ZIP files within the initial extracted files and copies those to a working directory
  • Then it deletes ZIP files from source, and extracts the other zip files from working directory and loops until complete

Note: The 7za executable file may either need to be copied to the /system32 folder or you may need to set the path it resides into the PATH environment variable.


Batch Script

You will need to set the source, destination, and working directory variable values accordingly for your environment and needs only and the rest should just work as expected.

@ECHO ON

SET sourcedir=C:\Test\Source
SET destdir=C:\Test\Dest
SET workdir=C:\Test\WorkTemp

:unzip
7za -Y e "%sourcedir%" -o"%destdir%" -r
DEL /Q /F "%workdir%\*zip
XCOPY /Y /F %destdir%\*.zip "%workdir%"
DEL /Q /F %destdir%\*.zip

DIR "%workdir%\*.zip" /A-D                         
IF ERRORLEVEL 1 GOTO :done

:unzip2
7za -Y e "%workdir%" -o"%destdir%" -r
DEL /Q /F "%workdir%\*.zip"
XCOPY /Y /F %destdir%\*.zip "%workdir%"
DEL /Q /F %destdir%\*.zip

DIR "%workdir%\*.zip" /A-D                         
IF ERRORLEVEL 1 GOTO :done
GOTO :unzip2

:done
GOTO :EOF

Further Resources

  • XCOPY
  • DEL
  • ERRORLEVEL
  • 7ZA COMMANDS