Xceed Zip Compression Library Documentation
PreviewFiles method and PreviewingFiles event example for Delphi
Example topics > PreviewFiles method and PreviewingFiles event example for Delphi

 The first function of the following code previews all the files that match the "C:\DATA\*.dat" wildcard and that are bigger than 65536 bytes. Keep in mind that any subdirectories in C:\DATA will also be searched for *.dat files, because the ProcessSubfolders property is set to True by default, even if the code below doesn't explicitly set it. The second function below is a handler written for the PreviewingFile event that displays each file previewed, along with some other of the file's information, in a listbox. The third function below is a handler written for the ProcessCompleted event, that adds summary information into the same listbox. The code assumes you have placed a button, a listbox and an Xceed Zip control on a form, and named them Button1, ListBox1 and XceedZip1 respectively.

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

Delphi Copy Code

procedure Tform1.Button1Click(Sender: Tobject);

var   ResultCode : integer;  

   begin
      XceedZip1.License( 'your license key' ); 

      XceedZip1.FilesToProcess := 'c:\data\*.dat'; 
      XceedZip1.MinSizeToProcess := 65536
      { Added this as an example of what you can do with the PreviewFiles method }  

      { We don't need to set the ZipFilename property, because PreviewFiles doesn't look at what's in the Zip file already. }  

      { Now call the PreviewFiles method without the optional parameter } 
      ResultCode = XceedZip1.PreviewFiles  

      { If we wanted to know the total compressed size of all the previewed files, we could have used this line instead: } 

      { ResultCode = XceedZip1.PreviewFiles(True); } 

      { If you do this, the ProcessCompleted event's lBytesOutput parameter will contain the total compressed size. }  

      { Now we check the return value } 
      If ResultCode <> xerSuccess Then 
         ShowMessage('Unsuccessful. Error #'+IntToStr(ResultCode))
      Else 
         ShowMessage('Operation successful.'); 
   end;
end;

Here's the handler for the PreviewingFile event. It will add each previewed file's name and info to the listbox.

Delphi Copy Code

procedure TFOrm1.XceedZip1PreviewingFile(Sender: Tobject; const sFilename, sSourceFilename: WideString; lSize: Integer; xAttributes: ToleEnum; dtLastModified, dtLastAccessed, dtCreated: TdateTime; bExcluded: WordBool; xReason: ToleEnum);

begin
   ListBox1.Items.Add('Filename : ' + sFilename); 
   ListBox1.Items.Add('Date : ' + dtCreated); 
   ListBox1.Items.Add('Size : ' + lSize); 
end;

Here's the handler for the ProcessCompleted event. It adds summary information to the listbox.

Delphi Copy Code

procedure TFOrm1.XceedZip1ProcessCompleted(Sender: Tobject; lFilesTotal, lFilesProcessed, lFilesSkipped, lBytesTotal, lBytesProcessed, lBytesSkipped, lBytesOutput: Integer; nCompressionRatio: SmallInt; xResult: ToleEnum);

begin

   ListBox1.Items.Add('=====================================" 
   ListBox1.Items.Add('Summary : '); 
   ListBox1.Items.Add(''); 
   ListBox1.Items.Add('Total number of Files :' + lFilesTotal); 

   ListBox1.Items.Add('Total compressed Size : ' + lBytesOutput); { This information is only valid if you called the PreviewFiles method with the optional parameter set to True } 

end;