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
This question is related to
command-line
7zip
I've not looked into this but shooting from the hip I'd say that they dropped command line support in the portable. The reason people don't do much command line stuff in portable applications is that the OS (windows in your case) requires that executables be added to the %path% inclusion list.
If that requirement is not met using command line utilities is rather tedious.
7z -a .
would be
d:\portable\z7\z7 -a c:\to\archive\folder*.*
Typing that out for everything is why GUI's make sense with things like portable apps it (the app) can remember it's own location and handle that stuff for you and if you can't run it you know it's not attached.
If you really want the portable app to contain that though you can always install the full version and pull the required 7z.exe out and put it into the portable folder making sure it's in with the required dll's.
You'll have to set your path when you hit the shell after making sure it's attached.
http://www.redfernplace.com/software-projects/patheditor/ -- a good path editor (down) usefull if you have lots of path information 20+ get's hard to read.
http://www.softpedia.com/get/System/System-Miscellaneous/Path-Editor.shtml -- alternet source for path editor
It's not advisable to modify your system path for temproary "portable" drives though manualy do that by:
set path=%path%;"d:\portable\z7\";
when you run dos cmd.exe or http://sourceforge.net/p/conemu/home/Home/
The other answers address other problems better I'm not going to try..
http://www.codejacked.com/zip-up-files-from-the-command-line/ -- good reference for command line usage of z7 and z7a.
PS: sorry for the necro but I figured it needed a more direct answer to why (even if it's just speculative).
The command-line program for 7-Zip is 7z or 7za. Here's a helpful post on the options available. The -r (recurse) option stores paths.
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:
C:\
, one for D:\
, etc)cd /d C:\
)C:\Foo\Bar
becomes Foo\Bar
)7z a archive.7z @filelist
as before with this new file listtry this one. it worked for me. 7z.exe a d:\newFileName.7z "d:\ExistingFile.txt"
open cmd and if you have installed 7zip app then try this. on command prompt it will like c:\programs and files\7zip\7z.exe a d:\newFileName.7z "d:\ExistingFile.txt"
Since 7-zip version 9.25 alpha there is a new -spf
switch that can be used to store the full file paths including drive letter to the archive.
7zG.exe a -spf c:\BAckup\backup.zip @c:\temp\tmpFileList.txt
should be working just fine now.
7-Zip wants relative paths in the list file otherwise it will store only the filenames, causing duplicate file name error.
Assuming that your list contains full path names:
If your list file has paths relative to another folder, you should be running 7Z from that folder.
Update: I noticed from another post above that the new 7-Zip has an -spf option that doesn't require the above steps. Not tested it yet but my steps are for earlier versions that do not have this option.
Instead of the option a
use option x
, this will create the directories but only for extraction, not compression.
Source: Stackoverflow.com