Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

How to compress a directory with 7zip and give the archive file the name of the current directory?

I use the following command line:

"C:\Program Files\7-Zip\7z.exe" a -mx9 archive.7z -mhe=on

Instead of "archive.7z" I need the name of the current directory.

For example, if I compress the directory: "C:\test 1\test 2\test 3", the filename should be "test 2.7z".

share|improve this question

migrated from Jul 12 '11 at 15:19

This question came from our site for professional and enthusiast programmers.

are you doing this from a batch file? – Kevin Jul 12 '11 at 15:25

Try using "%~n1" in place of the filename. Use quotes, as there may be spaces in the path.

This can only be used in a batch script and not interactively, and you need to use %CD% or . as the parameter passed.


my7zscript.bat %cd%
my7zscript.bat .
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.