Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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

1 Answer 1

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.

eg.

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

Your Answer

 
discard

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