5

I want to compress all HTM files in D:\HTM\ to an archive called comp.7z which is created in D:\HTM\ directory, so I do the following:

7z a -o "D:\HTM" comp.7z "D:\HTM"

and get an error, exactly as below:

Error:
Incorrect command line

Why am I getting error, what is the correct way/syntax of using -o switch?

I have tried:

7z a -o"D:\HTM" comp.7z "D:\HTM"

And:

7z a -o{"D:\HTM"} comp.7z "D:\HTM"

It creates comp.7z in CWD.

  • Please write even the error you received editing your post. Did you try 7z a D:\Your\full\path\com.7z D:\HTM\*.htm ? – Hastur Apr 20 '15 at 17:22
  • @Hastur, I didn't quite understand write even the error you received. The "Error:\nIncorrect command line" is what the output was. – RinkyPinku Apr 20 '15 at 17:27
  • My fault, I expected 7z a little more loquacious. :-) – Hastur Apr 20 '15 at 17:33
  • Always read the manual! -o (set Output directory) switch: Specifies a destination directory where files are to be extracted. This switch can be used only with extraction commands (e and x). – Karan Apr 20 '15 at 18:10
  • 1
    @Karan always read the question first. Using -o was one of my attempts to get desired output paths. Also try 7z --help & see the output, one of the line says ` -o{Directory}: set Output directory`. – RinkyPinku Apr 21 '15 at 1:49
6
7z a D:\HTM\comp.7z D:\HTM\*.htm

You don't need the -o since you're creating an archive. You also fail to specify which files need to be included in the archive (D:\HTM\*.htm). The output is the complete name of the archive (D:\HTM\comp.7z). The quotes aren't needed here, since there are no spaces in the filename(s).

  • Great answer! Everyone was neglecting to mention that -o is only for extracting! – JGlass Jan 26 '19 at 21:23

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.