I want to create a 7zip file containing files with the same names but in different folders using 7zip's @listfile feature. Although I have used 7zip CLI for a long time, I just cannot find the syntax to accomplish this.
My file tree looks like this (note that somefile1.html and somefile2.html occur twice each).
| somefile2.html
+---dir1
| somefile1.html
| somefile2.html
|
+---dir2
| somefile3.html
| somefile4.html
|
\---dir3
somefile1.html
somefile5.html
Using a @listfile works fine, but I cannot figure out how to retain the directory tree in the resulting 7zip while doing that.
I have tried to the following syntax:
7z a [email protected] my_compressed_file.7z
Then, given the explanations in 7zip's Windows CHM help file under syntax, I tried including the root folder, too (called 'files'):
7z a [email protected] my_compressed_file.7z .\files
I get the same error in both cases:
Error
Duplicate filename:
somefile1.html
somefile2.html
Has anyone figured this one out and would care to shed some light on it?
I know how to compress files with the same names in different folders otherwise (when the folder structure is retained in the 7zip it s no problem). But this time the few files I need are spread all over the place...
The following commands for windows, using the shell and 7za (the command-line version of 7zip) could probably be adapted for other platforms; but this solved the problem for me:
1) Make a list of all the files you want to archive, including full paths, with a command like the following; suppose your command prompt is in the C:\ directory and you want to list all *.xmp files in all sub-directories on the C: drive, for archiving in the next step:
DIR /B /S *.xmp > XMPsToArchiveList.txt
2) Use XMPsToArchiveList.txt as the list file for 7za, with the -spf switch, which instructs 7za to "use fully qualified file paths:"
7za a -spf [email protected] allCdriveXMPs.7z
If all goes well, you should receive the blissful message: "Everything is OK," and see a new and proper so named .7z archive.
In my test, the resulting .7z archive has folders and sub-folders reflecting the full paths to all .xmp files, with the root folder titled "C:".
NOTES:
A) On Windows, to adapt the list command to include everything in so many directories of a given name (in so many different places), you can use e.g.:
DIR /S /B *_aCertainFolderNameDuplicatedAllOverTheDrive* > foldersToArchive.txt
B) The -spf switch was added 2011-09-16; re: http://www.7-zip.org/history.txt
Also, I tried wildcards trying to produce a list like you describe, but didn't have any luck getting all files named e.g. somefile*.txt into a list (such as archiveTheseFiles.txt). Maybe I mis-typed? Seems simple. You'll need to mess around at the prompt to find what works for you.
Finally, I don't know whether the -spf switch is available for 7z (as opposed to 7za). 7za is available yonder, in the "extras" download: http://www.7-zip.org/download.html
I ran into the same error (Duplicate filename) while using a list file. My list file looked like this:
D:\SomeDir\SomeFile.txt
D:\SomeOtherDir\SomeFile.txt
I resolved the problem by launching 7-zip from D:\ and editing my list file to use relative rather than absolute paths:
SomeDir\SomeFile.txt
SomeOtherDir\SomeFile.txt
The resulting archive preserved the original directory structure and looked exactly as I expected.
Note: I was using 7-Zip 4.65, and this solution will not work if the files are on different drives or have a different root.
The PowerShell command line I ran was:
& 'C:\Program Files\7-Zip\7z.exe' a -scsWIN logs.7z `@recentlogs.txt
My real directory structure was:
+---Release
| | Lib.dll
| \--- x64
| Lib.dll
|
+---Definition_files
| data_files
|
+---x64
| Lib.dll // Copy of the previous file (only to preserve "x64" directory")
\---Documentation
documentation_files....
I used the list file:
.\Release\Lib.dll // used ".\" to remove "Release" directory
Definition_files\data_files
Documentation\documentation_files
x64\Lib.dll
Commandline:
7z.exe a -mx=9 -mpass=5 -r .\Packgakes\release.zip [email protected]
This caused a duplicity error. Without "-r" there is no error.
Try to check command line for recursive scan and list of files if there really are not two files with the same destination path (using "." in file path removes path in output).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With