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".

link|improve this question
are you doing this from a batch file? – Kevin Jul 12 '11 at 15:25
feedback

migrated from stackoverflow.com Jul 12 '11 at 15:19

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

1 Answer

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 .
link|improve this answer
feedback

Your Answer

 
or
required, but never shown