How to use zipper to add files to existing zipfile? lazarus / 21-General ---------------------------------------------------------------------- BosseB · 2021-03-29 16:10 I have a service application I am trying to port to Linux. I use Lazarus 2.0.8 and Fpc 3.0.4 in this case but I will upgrade when I am done porting. So this application commands exeternal equipment to do some measures and returns the resulting data to the server. Now these data are packaged into several files (mostly text files), which are supposed to go into a zip file on the output directory. This seemed to work fine until I found that some files were missing in the zipfile. The zip is created in two passes, one when the pure binary communication stream is available as binary data in a few *.bin fiiles. Then these are put into the output zipfile. Next the processing of the binary data is done and results in the other set of output files, which are also put into the same zipfile. Only, when I inspect the zipfile only the files written the second time are present.. So I wonder if there is some flag of some kind I have missed to do an append zip operation? This is the function I use for putting files into a zip archive (argument FileList contains a list of the paths to all files to be included in the zip archive): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i implementationuses  Zipper;procedure PrintMessage(Msg: string);{This will show the Msg string on the console window if running on acommand line program, else nothing}begin  {$IFDEF CONSOLE}  Writeln(Msg);  {$ENDIF}end; function ZipFiles(TargetFile: string; FileList: TStrings): boolean;var  {$ifdef FPC}  ZW: TZipper;  {$else}  ZW: TZipWrite;  {$endif}  i: integer;  FileName,  BaseArcFile,  ArcFileName,  LastError: string;begin  Result := false;  {$ifdef FPC}  ZW := TZipper.Create;  {$else}  ZW := TZipWrite.Create(TargetFile);  {$endif}  try    PrintMessage('Zipping files to: ' + TargetFile);    try      {$ifdef FPC}      ZW.FileName := TargetFile;      BaseArcFile := IncludeTrailingPathDelimiter(ChangeFileExt(ExtractFileName(TargetFi le), ''));      {$endif}      for i := 0 to FileList.Count-1 do      begin        FileName := FileList[i];        if not FileExists(FileName) then Continue;        {$ifdef FPC}        ArcFileName := BaseArcFile + ExtractFileName(FileName);        PrintMessage('Add file to zip: ' + FileName);        ZW.Entries.AddFileEntry(FileName, ArcFilename);        {$else}        ZW.AddDeflated(FileName);        {$endif}      end;      {$ifdef FPC}      ZW.ZipAllFiles;      {$endif}      Result := true;    except      on E: Exception do      begin        LastError := 'Zip error: ' + E.Message;        PrintMessage(LastError);        exit;      end;    end;  finally    ZW.Free;  end;end;  Here is a sample of the console output when I run the program. There are two separate instances in the process when the zipfile is written too, first when the binary data has arrived (the bin files are saved to the zip archive) and next after the data have been analyzed and the output text files created: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Zipping files to: /agi/ssremote/results/FirstTest_20210329_105418.zipAdd file to zip: /agi/ssremote/results/FirstTest_20210329_105418.stg.binAdd file to zip: /agi/ssremote/results/FirstTest_20210329_105418.cmd.binAdd file to zip: /agi/ssremote/log/CmdDir.binAdd file to zip: /agi/ssremote/log/FileDir.binAdd file to zip: /agi/ssremote/log/Calib.binZipping files to: /agi/ssremote/results/FirstTest_20210329_105418.zipAdd file to zip: /agi/ssremote/results/FirstTest_20210329_105418.stgAdd file to zip: /agi/ssremote/results/FirstTest_20210329_105418.cmdAdd file to zip: /agi/ssremote/results/FirstTest_20210329_105418.crs So now I expected that the zip contained 5 bin files and 3 text files, but in fact only the 3 text files appear. It seems like if I call the ZipFiles twice with the same target name if the file exists it will be overwritten rather than appended to. Question: Is there a setting in Zipper that allows for adding extra files into an existing zip archive file? ---------------------------------------------------------------------- wp · 2021-03-29 16:40 My feeling is that zipper can only create new files. So, in order to append to an existing zip, you must first use the unzipper to extract the files from the existing archive. Then you can use zipper to pack both old and new files into a new archive. Not very comfortable, I guess. Of course you can alternatively execute a commandline zip utility by means of TProcess. ---------------------------------------------------------------------- trev · 2021-03-29 23:50 Delay zipping until all wanted files are available. Simples (I assume not relying on an external dependency was the point of using zipper.) ---------------------------------------------------------------------- BosseB · 2021-03-30 06:06 I have walked over the code and added in the missing files in the second invocation of the ZipFiles function so it actually makes a full file rather than appending the new files into the zip. Since it is existing code using a class that is originally used stand- alone it is not so simple to only make one call, they come from different classes. But now the last call makes the final report file containing all needed files. Now working (end result is OK) even though it does unnecessary operations in this case. Will try to refactor later.