Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.0.0+

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

CkZip_Dispose(zip);
CkZipEntry_Dispose(entry);