3

I would like to use a .bat file to unzip a ZIP compressed archive file if possible at all. Nothing fancy, I just want to extract the entire archive file to the same location, i.e. download a .zip file to desktop and want to extract it next to desktop with the same name.

I tried this, but with no success.

for /R "C:\Users\Desktop\test.zip" %%I in ("*.zip") do(
   "%ProgramFiles(x86)%\7-zip\7z.exe" x - y -o"%%~dpnI" "%%~fI"
)
exit
Mofi
  • 46,139
  • 17
  • 80
  • 143
adamrowe16495
  • 55
  • 1
  • 5

1 Answers1

1

You shouldn't need the loop. Depending on whether you want to extract the directory structure contained within the archive or just extract everything to a single directory, you would use:

7z e C:\Users\Desktop\test.zip -o C:\Users\Desktop\test

or

7z x C:\Users\Desktop\test.zip -o C:\Users\Desktop\test

See https://sevenzip.osdn.jp/chm/cmdline/commands/index.htm for a list of commands and drill down as needed for the various options.

You should not need a for loop in your batch file, unless you intend to only extract files based on a list of patterns.

jwdonahue
  • 6,199
  • 2
  • 21
  • 43