Create an 7zip archive in Delphi

Viewed 462

I use this 7zip wrapper for Delphi 7 which works fine

https://github.com/zedalaye/d7zip

It creates archive but overwrites files already inside

var
  Arch: I7zOutArchive;
 begin
  Arch := CreateOutArchive(CLSID_CFormat7z);
  SetCompressionLevel(Arch, 2);
  Arch.AddFile('C:\Test.bin', 'Test.bin');
  Arch.SaveToFile('C:\Test.zip');
 end;

It removes all other files saved in 'Test.zip' Is there anyway i can keep files inside 'Test.zip' and write new file with this wrapper in Delphi 7

1 Answers

The wrapper you are using does not allow you to update an existing archive, only to create a new archive. So, to add files to an existing archive, you would have to do the following:

  • use CreateInArchive() to open the existing archive
  • use CreateOutArchive() to create a new temp archive
  • copy files from the input archive to the output archive
  • add files to the output archive
  • close both archives
  • replace the old archive with the new archive
Related