How to Avoid 7zip 'Duplicate filename' Error





4.00/5 (3 votes)
Avoid 7zip 'Duplicate filename' error when creating an archive with files from multiple directories.
Introduction
When trying to zip multiple directories containing files with the same names using a batch file with 7zip, I encountered an unexpected 'Duplicate filename' error.
I searched the internet for a solution, but could not find an elegant solution.
Using the Code
The batch file, see below, should update an archive and when files with the same name are found, update it with the most recent file.
Although the syntax is correct, the first example with all directories on the same line will fail to update the files correctly:
Rem This does not work.
del Test.zip
"C:\Program Files\7-Zip\7z.exe" u Test.zip C:\Temp\One\*.pdb C:\Temp\Two\*.pdb
The solution is simple, split up the command and use only one directory per line:
Rem This works.
del Test.zip
"C:\Program Files\7-Zip\7z.exe" u Test.zip C:\Temp\One\*.pdb
"C:\Program Files\7-Zip\7z.exe" u Test.zip C:\Temp\Two\*.pdb
As can be seen in the output below at the bottom lines, one file is updated and one file is added: