Say have an executable target.exe, is there any way to compress this file into target.zip without specify archive name(output name) by using 7zip command line?


I don't think it's possible with the command line utility alone. The a command expects an archive file name (to add to or create) and a list of files.

If you try without specifying an archive name, you get a System Error: Incorrect Function because the first argument expected is an archive name. If you specify an executable for example, it will say archive type not supported, as it will try to make a .exe archive.

However: 7-zip is open source software. You can modify how the a command works to expect different arguments, or even make a new switch of your own!

Here's a Perl script I quickly threw together which should be able to do what you want:


use warnings;
use strict;

exit unless @ARGV;

my $path = "C:\\Program Files\\7-Zip\\7z.exe"; # modify this accordingly
my $infile = (split /\./,$ARGV[0])[0];

system("\"$path\" a $infile @ARGV");

The script will take the name of the first argument (before the . in the file name) and use that as the base for the archive name. I've assumed you're on Windows by the .exe reference, change the shebang line if not.

Place the script somewhere in your PATH and use it like so:

7z.pl target.exe otherfile someotherfile

It will create an archive named target.7z with those 3 files enclosed.

  • nice interesting solution – at. Mar 1 '10 at 21:31

What you're attempting to do is a gzip function. 7zip supports gzip as one of it's unzip methods although it doesn't support it a zip function. See the info here http://www.gzip.org/.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.