Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Iterate Over ZIP Entries Using EntryAt
This example demonstrates how to use the EntryAt method to iterate over all entries contained within a ZIP archive.
The EntryAt method retrieves a ZipEntry object for a given zero-based index.
This is useful for:
- Enumerating all entries in a ZIP archive
- Inspecting filenames, sizes, and timestamps
- Searching or filtering ZIP contents
Suppose the ZIP archive contains:
docs/readme.txt
images/logo.png
data/config.json The example loops through all ZIP entries and prints information about each entry.
Chilkat Lazarus Pascal 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;
numEntries: Integer;
entry: TZipEntry;
i: Integer;
begin
success := False;
// Open an existing ZIP archive.
zip := TZip.Create;
success := zip.OpenZip('example.zip');
if (success = False) then
begin
WriteLn(zip.LastErrorText);
Exit;
end;
// Get the total number of entries in the ZIP archive.
numEntries := zip.NumEntries;
WriteLn('Number of ZIP entries = ' + numEntries);
// Create a ZipEntry object that will be reused
// for each entry retrieved by EntryAt.
entry := TZipEntry.Create;
// Iterate over all ZIP entries.
i := 0;
while i < numEntries do
begin
// Retrieve the entry at index i.
success := zip.EntryAt(i,entry);
if (success = False) then
begin
WriteLn(zip.LastErrorText);
Exit;
end;
WriteLn('Entry ' + i);
WriteLn(' FileName: ' + entry.FileName);
WriteLn(' Uncompressed Length: ' + entry.UncompressedLength);
WriteLn(' Compressed Length: ' + entry.CompressedLength);
WriteLn('');
i := i + 1;
end;
// Sample output:
//
// Entry 0
// FileName: docs/readme.txt
// Uncompressed Length: 1204
// Compressed Length: 512
//
// Entry 1
// FileName: images/logo.png
// Uncompressed Length: 84211
// Compressed Length: 84102
//
zip.CloseZip();
WriteLn('Done.');
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.