Advertisement
zizzo81

Get list of files inside a ZIP

Dec 22nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.84 KB | None | 0 0
  1. uses
  2.   System.Zip;
  3.  
  4. function ListZipFiles(const AFilename: String; AFiles: TStrings): Boolean;
  5. var
  6.   Z: TZipFile;
  7.   I: Integer;
  8. begin
  9.   Result := False;
  10.   Z := TZipFile.Create();
  11.   try
  12.     if Z.IsValid(AFilename) then begin
  13.       try
  14.         Z.Open(AFilename, zmRead)
  15.       except
  16.         Exit
  17.       end;
  18.       Result := True;
  19.       if AFiles <> nil then begin
  20.         AFiles.BeginUpdate();
  21.         try
  22.           AFiles.Clear();
  23.           for I := 0 to Z.FileCount - 1 do
  24.             AFiles.Add(Z.FileName[I])
  25.         finally
  26.           AFiles.EndUpdate()
  27.         end
  28.       end
  29.     end
  30.   finally
  31.     Z.Free()
  32.   end
  33. end;
  34.  
  35. procedure TForm1.FormCreate(Sender: TObject);
  36. var
  37.   SL: TStringList;
  38. begin
  39.   SL := TStringList.Create();
  40.   if ListZipFiles('e:\test\file.zip', SL) then
  41.     ShowMessage(SL.Text);
  42.   SL.Free()
  43. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement