Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Create Zip Excluding Files Matching Patterns
See more Zip Examples
How to create a .zip archive excluding (skipping) files that match a set of wildcarded patterns.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.StringArray,
Chilkat.Zip;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
zip: TZip;
sa: TStringArray;
recurse: Boolean;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
zip := TZip.Create;
success := zip.NewZip('test.zip');
if (success <> True) then
begin
WriteLn(zip.LastErrorText);
Exit;
end;
// Create a string array object with our set of filename patterns
// to be excluded:
sa := TStringArray.Create;
success := sa.Append('*.bak');
success := sa.Append('*.tmp');
// Tell the zip object to use these exclusions:
zip.SetExclusions(sa);
// Append a directory tree. The AppendFiles does
// not read the file contents or append them to the zip
// object in memory. It simply appends references
// to the files so that when WriteZip (or WriteZipAndClose,
// or WriteExe, etc.) is called, the files are compressed
// and encrypted.
recurse := True;
success := zip.AppendFiles('/temp/a/*',recurse);
success := zip.WriteZipAndClose();
if (success <> True) then
begin
WriteLn(zip.LastErrorText);
Exit;
end;
WriteLn('Zip Created!');
zip.Free;
sa.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.