7-zip commandline

Arnold picture Arnold · Sep 2, 2009 · Viewed 111.2k times · Source

I'm creating a backup utility that zips all the files listed in a text file. I am using MS ACCESS as my front-end and 7-Zip for compression. These are the commands I am using:

7zG.exe a c:\Backup\backup.zip
@c:\temp\tmpFileList.txt

All the files are compressed without their path. Is there a way to include the path for each file in the zip file? Then when backup.zip is extracted the files would be restored to their original folder structure.

Thanks

Answer

Anonymous picture Anonymous · Apr 29, 2012

In this 7-zip forum thread, in which many people express their desire for this feature, 7-zip's developer Igor points to the FAQ question titled "How can I store full path of file in archive?" to achieve a similar outcome.

In short:

  • separate files by volume (one list for files on C:\, one for D:\, etc)
  • then for each volume's list of files,
    1. chdir to the root directory of the appropriate volume (eg, cd /d C:\)
    2. create a file listing with paths relative to the volume's root directory (eg, C:\Foo\Bar becomes Foo\Bar)
    3. perform 7z a archive.7z @filelist as before with this new file list
    4. when extracting with full paths, make sure to chdir to the appropriate volume's root directory first