4

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? :)

Margo
  • 672
  • 3
  • 13
  • 30
  • Are you on windows or linux (it might not affect the solution but sometimes command arguments/options syntax could vary) Seems like it's windows actually, with `%` syntax :) – JScoobyCed Oct 30 '13 at 07:15
  • Seems like it is not supported. You might need to extract, then robocopy (`robocopy c:\Sourcepath c:\Destpath /E /XC /XN /XO` see http://stackoverflow.com/a/4228925/1012381) the new files then archive the result – JScoobyCed Oct 30 '13 at 07:25
  • You can list the files through `find or findstr` and detect the filename of the file you want to add. If it exists, abort, if not then go ahead and repack the file. – foxidrive Oct 30 '13 at 11:40

1 Answers1

11

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.

MC ND
  • 69,615
  • 8
  • 84
  • 126