Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
List Files in a .zip
See more Zip Examples
How to list files within a .zipChilkat 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.ZipEntry,
Chilkat.Zip;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
zip: TZip;
n: Integer;
entry: TZipEntry;
i: Integer;
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.OpenZip('a.zip');
if (success = False) then
begin
WriteLn(zip.LastErrorText);
Exit;
end;
// Get the number of files and directories in the .zip
n := zip.NumEntries;
entry := TZipEntry.Create;
i := 0;
while i < n do
begin
zip.EntryAt(i,entry);
if (entry.IsDirectory = False) then
begin
// (the filename may include a path)
WriteLn(entry.FileName);
end;
i := i + 1;
end;
zip.Free;
entry.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.