zipping files with the same name in different folders using 7z @listfile feature
7zip, compression, directory, duplicates
Solution
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 -ir@XMPsToArchiveList.txt 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
Problem
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 -ir@files.txt 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 -ir@files.txt 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...