Sample code for 30+ languages & platforms
PowerBuilder

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.txt located beneath the docs subdirectory

When the ZIP archive is extracted:

  • emptyDir will be created as an empty directory.
  • docs/empty.txt will be created as an empty file under the docs subdirectory.

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Zip

li_Success = 0

loo_Zip = create oleobject
li_rc = loo_Zip.ConnectToNewObject("Chilkat.Zip")
if li_rc < 0 then
    destroy loo_Zip
    MessageBox("Error","Connecting to COM object failed")
    return
end if

li_Success = loo_Zip.NewZip("emptyEntries.zip")
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    return
end if

// Add an empty directory entry named "emptyDir".
li_Success = loo_Zip.AddEmpty(1,"emptyDir")
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    return
end if

// Add an empty file entry named "docs/empty.txt".
li_Success = loo_Zip.AddEmpty(0,"docs/empty.txt")
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    return
end if

// Write the ZIP archive to disk and close it.
li_Success = loo_Zip.WriteZipAndClose()
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    return
end if

Write-Debug "ZIP archive created successfully."


destroy loo_Zip