Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

List Files in Zip using EntryAt / GetNext

See more Zip Examples

Demonstrates how to iterate over the files and directories in a zip archive using EntryAt/GetNext.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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;
  entry: TZipEntry;
  hasMoreEntries: Boolean;

begin
  success := False;

  //  This example assumes the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  zip := TZip.Create;

  success := zip.OpenZip('qa_data/zips/xml_files.zip');
  if (success = False) then
    begin
      WriteLn(zip.LastErrorText);
      Exit;
    end;

  entry := TZipEntry.Create;
  hasMoreEntries := zip.EntryAt(0,entry);
  while (hasMoreEntries = True) do
    begin
      if (entry.IsDirectory = False) then
        begin
          WriteLn(entry.FileName);
        end
      else
        begin
          WriteLn('(directory) ' + entry.FileName);
        end;
      hasMoreEntries := entry.GetNext();
    end;

  //  Sample output showing both file and directory entries:

  //  a1.xml
  //  b1.xml
  //  c1.xml
  //  (directory) dir1/
  //  dir1/a2.xml
  //  dir1/c2.xml
  //  (directory) dir2/
  //  (directory) dir2/dir3/
  //  dir2/dir3/c3.xml


  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.