How to specify relative path in 7-zip command line?

4

1

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.

Kugel

Posted 2011-01-27T08:46:03.727

Reputation: 513

Answers

1

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.

Jeremy Sturdivant

Posted 2011-01-27T08:46:03.727

Reputation: 2 108

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 – 2011-01-27T11:59:00.927

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 – 2011-01-27T12:03:31.387

I believe that both CLI and GUI use the same library rather than GUI talking to cli. – Kugel – 2011-01-27T12:06:54.193

@Kugel, that sounds very likely. Alas, it's a shame. – Tobias Plutat – 2011-01-27T12:08:43.223

0

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.

Dimitar II

Posted 2011-01-27T08:46:03.727

Reputation: 101

0

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:

doc\Text.txt
vid\movie.avi

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

Alex

Posted 2011-01-27T08:46:03.727

Reputation: 121