Xceed Zip Compression Library Documentation
ListZipContents method and ListingFile event example for Delphi
Example topics > ListZipContents method and ListingFile event example for Delphi

The first function of the following code lists all the files in the zip file "c:\test\my test.zip" that finish with ".txt". For each file listed, the ListingFile event will be triggered. The second function below is a handler written for the ListingFile event that displays each file listed, along with some other of the file's information, in a listbox. The code assumes you have placed a button, a listbox and an Xceed Zip control on a form, and named them Command1, ListBox1 and XceedZip1 respectively. 

We start with the handler for the button's click event. The code will start the listing.

Delphi Copy Code

procedure TForm1.Button1Click(Sender: TObject);

var

   ResultCode: xcdError;  

begin

   XceedZip1.License( 'your license key' ); 

   { All properties keep their default values except the two below } 
   XceedZip1.FilesToProcess := '*.txt'; 
   XceedZip1.ZipFilename := 'c:\test\my test.zip';  

   { Start listing } 
   ResultCode := XceedZip1.ListZipContents;  

   { Check the result code to make sure it worked properly } 
   if (ResultCode <> xerSuccess) then 
      Listbox1.Items.Add('An error or warning occured, or files were skipped.'); 
end; 

And here's the handler for the ListingFile event. It will add each file's name and info to the listbox.

Delphi Copy Code

procedure TForm1.XceedZip1ListingFile(XceedZip: TXceedZip; const FileStats: TXcdFileStats); 

begin

   ListBox1.Items.Add('Filename: ' + sFilename); 
   ListBox1.Items.Add(' Uncompressed size: ' + IntToStr(lSize)); 
   ListBox1.Items.Add(' Compressed size: ' + IntToStr(lCompressedSize)); 
   ListBox1.Items.Add(' Compresion ratio: ' +  IntToStr(nCompressionRatio)); 
end;