Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is the internal zip packer from Total Commander:

A picture of the Total Commander zip packer dialogue box.

However I want to use my 7zip packer. When I select 5 files, I get 5 separate .zip archives for each selected file. How do I do that in 7zip?

share|improve this question
up vote 23 down vote accepted

I am not sure you can do what you are suggesting using the graphical user interface, but you can certainly from the command line:

FOR %i IN (*.*) DO 7z.exe a "%~ni.7z" "%i"

You would need to change directory (the cd command) to the F:\Downloads directory first, or whatever directory you would want to perform the mass compression. Also, it is easy enough to substitute in *.exe or whatever extension you want to filter for to just compress those documents.

And the secret decoder ring:

  • %i is a variable that holds the file name for each step in the loop
  • (*.*) is the selection criteria, it could easily be *.exe or similar
  • 7z.exe is the command line version of 7-Zip
  • %~ni - this expands the %i variable to just the file name - no extension

If you wanted to just add the folders for a given directory, the command is a bit more complex as by default FOR just works with files. We need to feed it some additional information:

FOR /F "usebackq delims=?" %i IN (`DIR /B /A:D`) DO 7z.exe a "%i.7z" "%i"

This works because of a few pieces of what seems like magic:

  • /F tells FOR to iterate over the expanded value in ()
  • usebackq tells FOR that I am going to pass a command and use the output to iterate
  • delims=? tells FOR that I want to break tokens apart on the ? - an illegal character in file names and directories. I only want one token.
  • The /B in DIR is for bare format - just the name
  • The /A:D in DIR is for restricting the results by attribute, the D is for directories

If you want to encapsulate this inside of a batch file, the only change you will need to make is to double escape the %i variable:

FOR %%i IN (*.*) DO 7z.exe a "%%~ni.7z" "%%i"
share|improve this answer
Yea, except yours is 7z archive, I want a zip archive! So instead? – Grumpy ol' bear Jul 18 '11 at 17:38
Better yet, I want zip or 7z with ultra compression. AND pack it in d:\packed. But so far your method works! – Grumpy ol' bear Jul 18 '11 at 17:43
Got it, thank you! FOR %i IN (.) DO 7z.exe a "i:\packed\%~ni.7z" "%i" -mx9 – Grumpy ol' bear Jul 18 '11 at 18:01
By the way, can you show me how to do that in a batch file? i.e. sperate-archive.bat – Grumpy ol' bear Jul 18 '11 at 21:01
Thanks, and how do I add whole folders to that script, please? – Grumpy ol' bear Jul 19 '11 at 12:52

I like Goyuix's answer. However, if you are using Windows 7 (or have Power Shell installed) and also use the command-line version of 7-zip, 7za.exe, then you can run this command:

dir | ForEach-Object { & "7za.exe" a $_.BaseName $_.Name }

You can also change "dir" to "dir *.exe" to only select executable files.

One nice thing about Power Shell is that you are working with objects instead of strings. So you could get really specific if you wanted to. For example:

dir *.csv | ? { $_.Length -lt 18900 -and $_.LastWriteTime -ge [DateTime] "07/01/2011" } | ForEach-Object { & "7za.exe" a $_.BaseName $_.Name }

This will only include files that:

  1. have a csv extension
  2. less than 18,900 bytes in size
  3. last modified on or after 7/1/2011

EDIT If you want zip files instead of 7-zip files, use InfoZip's zip.exe instead.

share|improve this answer
7-zip can also create zip files - have a look at the -t flag. Example: 7z a -tzip *.exe – Goyuix Jul 18 '11 at 22:48
Ok, $_.BaseName $_.Name works, but how do I do $_.BaseName $_.Name on another drive, in another directory? Say f:\test\file1.7z etc. – Grumpy ol' bear Jul 20 '11 at 9:06

You can download and install 7zip plugin for Total Commander from Once you do that on the right side of the window from your screenshot there will be another selection for 7zip compression. With that option you can accomplish exactly what you are asking for.

share|improve this answer

You must log in to answer this question.

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