I like 7-zip and I needed it's command line today. I bumped into a problem.

Is there a way to specify a path within archive when compressing?

For example I have a file at C:\some_dir\my_file.txt. When compressing I want to specify destination path to be \other_dir\my_file.txt within archive.

Is this possible? This seems like fairly common thing to do.


Neither the 7zip utility, nor any archiver I know of supports this directly. You can, however, create a directory structure matching what you would like in the archive, copy files into place, and archive that instead... Quite sad, in any case, seeing functionality present in the GUI, yet missing on the command line.

|improve this answer|||||
  • I ran into a similar program recently and wondered... can it really be that the CLI doesn't support this? As far as I understood it, the GUI is just a front-end for the CLI... or isn't it? – Tobias Plutat Jan 27 '11 at 11:59
  • The GUI might be taking the same approach, just using temp files... I know for the case of 7zip, the GUI can do this, while the CLI can not. That is to say, the GUI can directly rename and move files inside an archive. – Jeremy Sturdivant Jan 27 '11 at 12:03
  • I believe that both CLI and GUI use the same library rather than GUI talking to cli. – Kugel Jan 27 '11 at 12:06
  • @Kugel, that sounds very likely. Alas, it's a shame. – Tobias Plutat Jan 27 '11 at 12:08

You can use the 7zip's 'rn' command on the command line:

7z rn archive.7z my_file.txt \other_dir\my_file.txt

This will put your already compressed file in different (internal) archive folder. This works only on already created archive.

If you need 'other_dir' to be some relative path (not random directory), you can play with the current working directory and pass relative file names to that directory.

|improve this answer|||||

First create list file which contains the relative paths to the files to backup. Than use that list file as input file preceded by "@"

7zip.exe a archive.7z @listfile.txt

ListFile should look like this:


I did not test this with wildcards though. 7zip version was 18.05

|improve this answer|||||

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.