Windows script package for unpacking files in a directory

I want to unzip all files in a specific directory and save the folder names when unpacking.

The next batch of script does not quite do the trick. It just throws a bunch of files without putting them in a folder and not even ending.

What is wrong here?

for /F %%I IN ('dir /b /s *.zip') DO ( "C:\Program Files (x86)\7-Zip\7z.exe" x -y -o"%%~dpI" "%%I" ) 
+6
source share
4 answers

Try the following:

 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 to a folder with the name of the zip file):

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

The Ansgar answer above was perfect for me, but I also wanted to delete the archives afterwards if the extraction was successful. I found this and included it in the above to give:

 for /R "Destination_Folder" %%I in ("*.zip") do ( "%ProgramFiles%\7-Zip\7z.exe" x -y -aos -o"%%~dpI" "%%~fI" "if errorlevel 1 goto :error" del "%%~fI" ":error" ) 
+2
source

Try it.

 @echo off for /F "delims=" %%I IN (' dir /b /s /ad *.zip ') DO ( "C:\Program Files (x86)\7-Zip\7z.exe" x -y -o"%%~dpI\%%~nI" "%%I" ) pause 
+1
source

Is it possible that some of your zip files have a space in the name? If this is your first line should be:

 for /F "usebackq" %%I IN (`dir /b /s "*.zip"`) DO ( 

Note the use of `instead 'See FOR /?

-1
source

Source: https://habr.com/ru/post/947175/


All Articles