Click here to Skip to main content
15,881,882 members
Articles / Operating Systems / Windows
Tip/Trick

How to Avoid 7zip 'Duplicate filename' Error

Rate me:
Please Sign up or sign in to vote.
4.00/5 (3 votes)
11 Sep 2016CPOL 16.7K   3
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.

Image 1

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:

BAT
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:

BAT
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:

Image 2

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Netherlands Netherlands
Software developer in the Netherlands, currently working on Video Surveillance applications.
Experience: C#, C++, VB, ASP, SQL Server, PostgreSQL, Gitea, TeamCity.
It all started with Black&White, no not the whiskey but the Sinclair ZX81 followed by several Atari's and PC's. The journey continues ...

Comments and Discussions

 
GeneralMy vote of 1 Pin
Davor Poznič (kvidr)5-Mar-20 0:21
Davor Poznič (kvidr)5-Mar-20 0:21 
Questionunexpected? Pin
Member 1198573712-Sep-16 20:52
Member 1198573712-Sep-16 20:52 
AnswerRe: unexpected? Pin
RickZeeland12-Sep-16 20:58
mveRickZeeland12-Sep-16 20:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.