2

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

1
  • are you doing this from a batch file?
    – Kevin
    Jul 12, 2011 at 15:25

1 Answer 1

0

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 .

You must log in to answer this question.