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

Unzip a .zip Archive

See more Zip Examples

Demonstrates how to open a .zip archive and unzip. The Unzip method extracts the files and directories from a .zip archive and recreates the directory tree rooted at the directory path passed to Unzip.

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.Zip;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  zip: TZip;
  unzipCount: 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('my_files.zip');
  if (success <> True) then
    begin
      WriteLn(zip.LastErrorText);
      Exit;
    end;

  //  Returns the number of files and directories unzipped.
  //  Unzips to /my_files, re-creating the directory tree
  //  from the .zip.
  unzipCount := zip.Unzip('/my_files');
  if (unzipCount < 0) then
    begin
      WriteLn(zip.LastErrorText);
    end
  else
    begin
      WriteLn('Success!');
    end;


  zip.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.