Delphi DLL
Delphi DLL
Create Empty File and Directory Entries in a ZIP
See more Zip Examples
This example demonstrates how to use the AddEmpty method to create both empty directory entries and empty file entries within a ZIP archive.
The example creates:
- A truly empty directory named
emptyDir - An empty file named
empty.txtlocated beneath thedocssubdirectory
When the ZIP archive is extracted:
emptyDirwill be created as an empty directory.docs/empty.txtwill be created as an empty file under thedocssubdirectory.
It is not necessary to explicitly create the docs directory beforehand. The directory structure implied by the file path is created automatically when extracting.
Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Zip;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
zip: HCkZip;
begin
success := False;
zip := CkZip_Create();
success := CkZip_NewZip(zip,'emptyEntries.zip');
if (success = False) then
begin
Memo1.Lines.Add(CkZip__lastErrorText(zip));
Exit;
end;
// Add an empty directory entry named "emptyDir".
success := CkZip_AddEmpty(zip,True,'emptyDir');
if (success = False) then
begin
Memo1.Lines.Add(CkZip__lastErrorText(zip));
Exit;
end;
// Add an empty file entry named "docs/empty.txt".
success := CkZip_AddEmpty(zip,False,'docs/empty.txt');
if (success = False) then
begin
Memo1.Lines.Add(CkZip__lastErrorText(zip));
Exit;
end;
// Write the ZIP archive to disk and close it.
success := CkZip_WriteZipAndClose(zip);
if (success = False) then
begin
Memo1.Lines.Add(CkZip__lastErrorText(zip));
Exit;
end;
Memo1.Lines.Add('ZIP archive created successfully.');
CkZip_Dispose(zip);
end;