Reputation: 329
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
Upvotes: 13
Views: 137085
Reputation: 7107
I created the following batch file to utilize 7-Zip to zip up every subfolder into its own zip file, preserving the file structure. Since this demonstrates the commandline effectively, I thought it might help someone else to post it here.
@ECHO OFF
REM Cycle Through all of the directories in the current folder
for /D %%d in (*) do (
REM Change to the directory
pushd %%d
REM Make the destination directory.
mkdir "Z:\%%d"
REM Cycle Through all Subdirectories
for /D %%b in (*) do (
REM Zip up all subdirectores, and put it in the destination.
7z -r a "Z:\%%d\%%b.zip" %%b
)
popd
)
Upvotes: 0
Reputation: 898
try 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"
Upvotes: 1
Reputation: 572
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.
Upvotes: 0
Reputation: 5609
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.
Upvotes: 1
Reputation: 320
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).
Upvotes: 1
Reputation: 15
Instead of the option a
use option x
, this will create the directories but only for extraction, not compression.
Upvotes: -1
Reputation: 50369
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 listUpvotes: 6
Reputation: 99510
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.
Upvotes: 4