7zip or zip component lazarus / 31-LCL ---------------------------------------------------------------------- guest48704 · 2019-07-23 18:55 Is there a 7zip or zip component for lazarus?  Thanks ---------------------------------------------------------------------- wp · 2019-07-23 19:10 https://wiki.freepascal.org/paszlib ---------------------------------------------------------------------- Thaddy · 2019-07-23 19:12 There are several, including fully native. packages zlib, unzip and libtar come even as standard. (I am not complete). Start with zlib. ---------------------------------------------------------------------- guest48704 · 2019-07-23 20:20 Thanks. It isn't working correctly for me: Code: [Select]procedure TForm1.Test1Click(Sender: TObject); var OurZipper: TZipper; I: Integer; begin     OurZipper := TZipper.Create;     try       OurZipper.FileName := Application.Location + '\.UserKeys\archive.zip';       for I := 2 to ParamCount do           OurZipper.Entries.AddFileEntry(Application.Location + '\.UserKeys\john', Application.Location + '\.UserKeys\john2william');       OurZipper.ZipAllFiles;     finally       OurZipper.Free;     end; end;    It creates the archive.zip, but nothing is in it. ---------------------------------------------------------------------- wp · 2019-07-23 20:34 What are the parameters that you pass to the application? Note that the first parameter is not used ("for I := 2 to Paramcount...") Your code works correctly for me when I specify filenames directly. ---------------------------------------------------------------------- guest48704 · 2019-07-23 21:04 I was thinking that you could put a list of files in OurZipper.Entries.AddFileEntry.  This works ok: Code: [Select]procedure TForm1.Test21Click(Sender: TObject); var OurZipper: TZipper; I: Integer; begin     OurZipper := TZipper.Create;     try       OurZipper.FileName := Application.Location + '\.UserKeys\archive.zip';       OurZipper.Entries.AddFileEntry(Application.Location + '\.UserKeys\john');       OurZipper.Entries.AddFileEntry(Application.Location + '\.UserKeys\john2ann');       OurZipper.ZipAllFiles;     finally       OurZipper.Free;     end; end; ---------------------------------------------------------------------- wp · 2019-07-23 22:06 Quote from: lazarus9 on July 23, 2019, 11:04:02 pm I was thinking that you could put a list of files in OurZipper.Entries.AddFileEntry.  Yes. Why shouldn't this be possible? The problem in your example probably was that you did not pass parameters to your exe. Assuming that your project is called "zipper" (like in the wiki example, although not clearly specified there!) and you want to add the files "john" and "john2william" to the zip file you call the program like this: Code: [Select]  zipper john john2william This is valid for runtime. In your code the parameter "john" is available as ParamStr(1), the parameter "john2william" as ParamStr(2). If you want to use these parameters already in the IDE, go to "Run" > "Run parameters" and type "john johnwilliams2" (without quotes) into the box "Command line parameters". Then in the ButtonClick routine you add the path 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 procedure TForm1.Button1Click(Sender: TObject);var  OurZipper: TZipper; I: Integer;begin    OurZipper := TZipper.Create;    try      OurZipper.FileName := Application.Location + '\.UserKeys\archive.zip';      for i := 1 to ParamCount do        OurZipper.Entries.AddFileEntry(ParamStr(i));        // or add an extra path, or whatever you need:        // OurZipper.Entries.AddFileEntry(Application.Location + '\.UserKeys\' + ParamStr(i));      OurZipper.ZipAllFiles;    finally      OurZipper.Free;    end;end; Note that the index i begins here at 1, not at 2 like in your example. The value 2 was valid for the example in the wiki which you copied without thinking. The wiki project seems to create a binary "zipper" which expects the 1st commandline parameters to be the name of the zip file and the following parameters to be the names of the files to be added to the zip, like in zipper newzip.zip autoexec.bat config.sys Alternatively, you can pass a stringlist with file names to the method Entries.AddFileEntries, or shorter, to the method ZipFiles. You can populate the stringlist by calling the procedure FindAllFiles (in unit FileUtils). The following code packs all relevant source files of a project into archive.zip: 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 procedure TForm1.Button2Click(Sender: TObject);var  List: TStringList;  zip: TZipper;begin  List := TStringList.Create;  try    // Read all relevant file names of the project    FindAllFiles(List, Application.Location, '*.pas;*.lfm;*.lpr;*.lpi', false);      // false --> don't search subdirectories     zip := TZipper.Create;    try    zip.FileName := Application.Location + 'archive.zip';      zip.ZipFiles(List);      // or      {      zip.Entries.AddFileEntries(List);      zip.ZipAllFiles;      }    finally      zip.Free;    end;  finally    List.Free;  end;end;