Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add files to zip without overwriting if already exists in batch script with 7zip

I'm writing a script that is adding some files to an existing zip with 7zip, but if there is a file match the file inside the zip will be overwritten. I don't want that, if the file with the same name is already there i want to skip it.

My code now is something like that:

%zipPath% a %zipfile%  "%%~F"  

Any ideas? :)

like image 601
Margo Avatar asked Jan 13 '23 01:01

Margo


1 Answers

There is a complete set of options to determine how to update the contents of the file. See -u (update options) in 7z help. The parameters you probably need are

7z a -up1q1r2x1y1z1w1 zipfile filesToAdd

Which keeps in archive (the 1 in the switch) files in case of no match (p), file does not exist on disk (q), file in archive is newer than on disk (x), file in archive is older than on disk (y), file in archive is the same that on disk (z), or if it can't be determined (w). In case of file not in archive (r), it is compressed (2).

Seems complicated, but it is perfectly documented in 7zip help.

like image 88
MC ND Avatar answered Feb 01 '23 18:02

MC ND