-2
for /r %%I IN (' *.zip ') DO (
"C:\Program Files\7-Zip\7z.exe" x -o"%%~dpnI" "%%I"
)
pause

Hi, I got this batch command online that unzips files recursively. I would like to understand what the For loop does in this case.

I'm asking this question because I receive errors when running the bat file because the command also picks folders and files of other extensions apart froma *.zip and throws the following error.

D:\Unzip_folders\New folder>("C:\Program Files\7-Zip\7z.exe" x -o"D:\Unzip_folders\New folder\23Nov2015\error_log.17112015\'" "D:\Unzip_folders\New folder\23Nov2015\error_log.17112015\'" )

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21

Scanning the drive for archives:

ERROR: The system cannot find the file specified.
D:\Unzip_folders\New folder\23Nov2015\error_log.17112015\'
  • Open a command prompt window, run there `for /?` and read the output help for this command explaining `%~dpnI` (drive letter, path and name without extension of found file) and `%I` (name of found file with extension. 7-Zip has a help explaining command `x` (extract) and switch `-o`. – Mofi Jun 14 '16 at 06:08

2 Answers2

0

if you analyze the error message, you notice a single ' at the end of each filename. That's because you use the wrong sort of quotes.

Skip them entirely:

for /r %%I IN (*.zip) DO (

or use doublequotes:

for /r %%I IN ("*.zip") DO (
Stephan
  • 53,940
  • 10
  • 58
  • 91
0
for /r %%I IN (*.zip) DO (
"C:\Program Files\7-Zip\7z.exe" x -o"%%~dpnI" "%%I"
)
pause

Your code is incorrect. This is the proper one.

Rishav
  • 3,818
  • 1
  • 31
  • 49