Sample code for 30+ languages & platforms
Delphi DLL

Change a Filename before Unzipping

See more Zip Examples

How to open a zip and modify the filename of one or more files within the zip before unzipping.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, ZipEntry, Zip;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
zip: HCkZip;
entry: HCkZipEntry;
numFilesUnzipped: Integer;

begin
success := False;

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

zip := CkZip_Create();

success := CkZip_OpenZip(zip,'test.zip');
if (success = False) then
  begin
    Memo1.Lines.Add(CkZip__lastErrorText(zip));
    Exit;
  end;

entry := CkZipEntry_Create();

success := CkZip_EntryOf(zip,'hamlet.xml',entry);
if (success = False) then
  begin
    Memo1.Lines.Add(CkZip__lastErrorText(zip));
    Exit;
  end;
CkZipEntry_putFileName(entry,'hamlet2.xml');

success := CkZip_EntryOf(zip,'helloWorld.pl',entry);
if (success = False) then
  begin
    Memo1.Lines.Add(CkZip__lastErrorText(zip));
    Exit;
  end;
CkZipEntry_putFileName(entry,'hw.pl');

// Now unzip to the "test" subdirectory, under our current
// working directory:
numFilesUnzipped := CkZip_Unzip(zip,'test');
if (numFilesUnzipped < 0) then
  begin
    Memo1.Lines.Add(CkZip__lastErrorText(zip));
    Exit;
  end;

// The filenames within the .zip are unchanged, but it unzipped
// test/hw.pl and test/hamlet2.xm

CkZip_Dispose(zip);
CkZipEntry_Dispose(entry);

end;