0

I have multiple .zip files which I want to unzip by a script. After a short research. I have this script:

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

The problem is, that it only unzips the files into the same folder. I have a designated folder for the unzipped files, can't get the script to move the files into that folder. Anyone has an idea what I need to add to this script?

Gunter
  • 137
  • 3
  • 12
  • What is the dedicated path to unzip to? `C:\root\folder`? – Gerhard Nov 16 '18 at 07:18
  • @GerhardBarnard The `C:/root/folder` is the folder where the .zip files are. Just for testing purpose I created a second folder `C:/root/folder2` in which these files should be unzipped – Gunter Nov 16 '18 at 07:22
  • then just specify that output directory. `7z.exe x -y -oc:C:\root\folder2 "%%~fI` – Gerhard Nov 16 '18 at 07:25
  • 1
    This is just blatant lack of understanding the code you are using, not reading the help file for 7zip and not searching SO for an answer. If my old memory serves me I have answered this same question about a half dozen times on SO. The path you mentioned in your comment isn't even in your code so this tells me you made no effort at all to solve your problem. – Squashman Nov 16 '18 at 13:46
  • The code itself already worked and I tried a bit but nothing of it worked. Why would I post a completely defect code which gave me no results? So I just posted the base code which worked and hoped someone could help me fill in the blanks – Gunter Nov 20 '18 at 07:54

1 Answers1

0

When reading the help for 7z in your cmd window, you will notice that the -o switch is the output directory option. Currently you are telling it to be %%~dpI which is in fact Drive and Path of the current of the zip files. So you would want to change the output directory:

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

I do not currently have 7zip installed, but I am almost 100% sure that it has a recursive function builtin, if so, you do not even need the for loop, you can just try:

7z.exe x -y "C:\root\folder\*.zip" -oc:"C:\root\folder2" -r

If it does not work, I will remove this section from the answer.

Gerhard
  • 22,678
  • 7
  • 27
  • 43