Windows batch script to unzip files in a directory


I want to unzip all files in a certain directory and preserve the folder names when unzipped.

The following batch script doesn’t quite do the trick. It just throws a bunch of the files without putting them into a folder and doesn’t even finish.

What’s wrong here?

for /F %%I IN ('dir /b /s *.zip') DO (

    "C:\Program Files (x86)\7-Zip\7z.exe" x -y -o"%%~dpI" "%%I" 


Try this:

for /R "C:\root\folder" %%I in ("*.zip") do (
  "%ProgramFiles(x86)%\7-Zip\7z.exe" x -y -o"%%~dpI" "%%~fI" 

or (if you want to extract the files into a folder named after the Zip-file):

for /R "C:\root\folder" %%I in ("*.zip") do (
  "%ProgramFiles(x86)%\7-Zip\7z.exe" x -y -o"%%~dpnI" "%%~fI" 

Answered By – Ansgar Wiechers

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published