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.

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?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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:

#!C:/Perl/bin/perl.exe

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.

share|improve this answer
    
nice interesting solution –  at. Mar 1 '10 at 21:31
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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

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