In this blog post, I will share a simple script to recursively unzip all ZIP files in sub-directories of a directory. Such script is useful for example when managing the submissions of papers at academic conferences. The script is based some code on StackOverflow.
FOR /D /r %%F in ("*") DO (
pushd %CD%
cd %%F
FOR %%X in (*.rar *.zip) DO (
"C:\Program Files\7-zip\7z.exe" x "%%X"
)
popd
)
IMPORTANT: Use this script at your own risk! Make a backup of your files before using the script in case something goes wrong!
This is for Windows. It assumes that you have 7ZIP installed on your computer and that the path to 7ZIP is correct. Save this script into a text file. Rename it to have the .bat extension. Then, double click on the file to run the script.
That is all!
—
Philippe Fournier-Viger is a distinguished professor working in China and founder of the SPMF open source data mining software.
The batch script did ruin anything, however it didn’t unzip folders as well. I created a better batch file, which doesn’t delete the zip-files afterwards, by the way:
@echo off
setlocal enabledelayedexpansion
set “file=”
for /f “delims=” %%a in (‘dir /b *.zip’) do (
set “file=%%~na”
)
if “%file%”==”” (
echo There are no .zip-files found in this directory.
pause
exit /b
)
for /f “tokens=1 delims=.” %%a in (‘dir /B *.zip’) do “C:\Program Files\7-zip\7z.exe” x “%%a.zip”