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:
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
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.sysAlternatively, 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:
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;