I solved this problem, see answer below. Now my question is, how to make it tolerate directories with spaces in the dir name.

I'm looking for a command line for 7zip that achieves the following: I have a base folder, containing many subfolders, each of which contains many zip files. Each zip file in turn contains many files. Like this:







[the same structure repeated for dir3, dir4...dirn]

What I'm trying to achieve is this.





In other words, each of the zip files have been unzipped into subfolders with the same name as the zip file. Those subfolders are in the same folder that each zip file was in.

I have tried this:

for /F "usebackq" %f in (dir /b/a:d) do C:\APPS\7-Zip\7z.exe x .%f*.zip -o%f

But this places all the unzipped files in the folder the zip is in (x1.zip gets unzipped to c:\base\dir1, z1.zip gets unzipped to c:\base\dir2, etc.) rather than into subfolders No subfolders named after the zip file are created. IOW this:

Incorrect 1:


etc. I also tried this:

for /F "usebackq" %f in (`dir /b/a:d`) do "C:\Program Files\7-Zip\7z.exe" x .\%f\*.zip -o*

Now subfolders named after the name of the zip file are indeed created, but all of them are in c:\base, like this:

Incorrect 2:



Again, what I'm going for is:


Sorry for this very longwinded post about what seems to be a fairly simple operation. I really struggled getting the formatting of my sample folder trees to look right, so apologies if they're confusing. If anyone knows how to do this, hopefully with the right command line, I'll be grateful.

  • Additional comment: the -o switch tells 7zip where to unzip to, so -o$f in this context unzips into the folder containing the zip file. -o* causes 7zip to unzip into new folders named after the zip file. I could find no way to combine these two operations: unzip into a new subfolder inside a specified folder.
    – Robert M.
    Sep 27, 2022 at 0:57

1 Answer 1


I figured it out. It's just:

for /F "usebackq" %f in (`dir /b/a:d`) do "C:\Program Files\7-Zip\7z.exe" x .\%f\*.zip -o%f\*

-o%f* creates a subfolder named after the zip file inside the folder the zip file is in.

Another question though, how can I make it tolerate directories with spaces in them?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .