[yunqa.de] Re: DIZIPWriter file exclusion

  • From: Andy Samuel <asorg@xxxxxxxxx>
  • To: "yunqa@xxxxxxxxxxxxx" <yunqa@xxxxxxxxxxxxx>
  • Date: Wed, 5 Mar 2014 11:00:04 -0800 (PST)

Oh, ok. Got it.

Thanks 





On Thursday, March 6, 2014 12:01 AM, Delphi Inspiration <delphi@xxxxxxxx> wrote:
 
On 05.03.2014 17:25, Andy Samuel wrote:

> How do I exclude certain files...like for example, *.exe ?

There is no need to exclude certain files with DIZipWriter. 
TDIZipWriter.AddFile('Filename') just adds the one file specified.

Your application can iterate the files in question (for example using my 
DIFileFinder component) and only call TDIZipWriter.AddFile() for those 
matching your criteria.

This is very easy with my DIFileFinder component: You can create an 
instance of TDIWildFileFinder and exclude *.exe files like this:

var
   cDeflate: TYuDeflateCompressor;
   FileFinder: TDIWildFileFinder;
   ZipWriter: TDIZipWriter;
begin
   ZipWriter := TDIZipWriter.Create(nil);
   try
     cDeflate := TYuDeflateCompressor.Create(nil);
     try
       ZipWriter.Compressor := cDeflate;

       ZipWriter.NewZipFile('ZipFile.zip');
       ZipWriter.BaseFolder := 'FolderWithFiles';

       FileFinder := TDIWildFileFinder.Create(nil);
       try
         FileFinder.SearchFolder := 'FolderWithFiles';
         FileFinder.Recurse := True;
         FileFinder.MatchType := mtSimpleName;

         FileFinder.ExcludeFilters.InsertNameLast('*.exe');

         while FileFinder.Next do
           begin
             ZipWriter.AddFile(FileFinder.FullName);
           end;

         ZipWriter.CloseZip;
       finally
         FileFinder.Free;
       end;
     finally
       cDeflate.Free;
     end;
   finally
     ZipWriter.Free;
   end;
end;


Ralf
_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa

Other related posts: