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

Iterate Over ZIP Entries Using EntryAt

This example demonstrates how to use the EntryAt method to iterate over all entries contained within a ZIP archive.

The EntryAt method retrieves a ZipEntry object for a given zero-based index.

This is useful for:

  • Enumerating all entries in a ZIP archive
  • Inspecting filenames, sizes, and timestamps
  • Searching or filtering ZIP contents

Suppose the ZIP archive contains:

docs/readme.txt
images/logo.png
data/config.json

The example loops through all ZIP entries and prints information about each entry.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Zip
long li_NumEntries
oleobject loo_Entry
long i

li_Success = 0

//  Open an existing ZIP archive.
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.OpenZip("example.zip")
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    return
end if

//  Get the total number of entries in the ZIP archive.
li_NumEntries = loo_Zip.NumEntries

Write-Debug "Number of ZIP entries = " + string(li_NumEntries)

//  Create a ZipEntry object that will be reused
//  for each entry retrieved by EntryAt.
loo_Entry = create oleobject
li_rc = loo_Entry.ConnectToNewObject("Chilkat.ZipEntry")

//  Iterate over all ZIP entries.
i = 0
do while i < li_NumEntries

    //  Retrieve the entry at index i.
    li_Success = loo_Zip.EntryAt(i,loo_Entry)
    if li_Success = 0 then
        Write-Debug loo_Zip.LastErrorText
        destroy loo_Zip
        destroy loo_Entry
        return
    end if

    Write-Debug "Entry " + string(i)
    Write-Debug "  FileName: " + loo_Entry.FileName
    Write-Debug "  Uncompressed Length: " + string(loo_Entry.UncompressedLength)
    Write-Debug "  Compressed Length: " + string(loo_Entry.CompressedLength)
    Write-Debug ""

    i = i + 1
loop

//  Sample output:
//  
//  Entry 0
//    FileName: docs/readme.txt
//    Uncompressed Length: 1204
//    Compressed Length: 512
//  
//  Entry 1
//    FileName: images/logo.png
//    Uncompressed Length: 84211
//    Compressed Length: 84102
//  

loo_Zip.CloseZip()

Write-Debug "Done."


destroy loo_Zip
destroy loo_Entry