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.

7
  • 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
    Commented Apr 20, 2015 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
    Commented Apr 20, 2015 at 17:27
  • My fault, I expected 7z a little more loquacious. :-)
    – Hastur
    Commented Apr 20, 2015 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
    Commented Apr 20, 2015 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
    Commented Apr 21, 2015 at 1:49

1 Answer 1

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .