Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to Avoid 7zip 'Duplicate filename' Error

0.00/5 (No votes)
11 Sep 2016 1  
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.

<img src="1127369/Test7zip1.png" style="width: 640px; height: 289px;" />

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:

<img src="1127369/Test7zip2.png" style="width: 640px; height: 581px;" />

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here