Sample code for 30+ languages & platforms
PowerBuilder

Iterate Through ZIP Entries Using EntryAt and ZipEntry.GetNext

See more Zip Examples

This example demonstrates how to iterate through all entries in a ZIP archive using:

  • Zip.EntryAt to obtain the first entry
  • ZipEntry.GetNext to advance through the remaining entries

The example prints each ZIP entry's stored filename and whether the entry is a file or directory.

This approach is useful when sequentially processing ZIP entries without repeatedly calling EntryAt by index.

Suppose the ZIP archive contains:

docs/
docs/readme.txt
images/logo.png
hello.txt

The example iterates through each entry in the order stored within the ZIP archive.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Zip
oleobject loo_Entry

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

// Open an existing ZIP archive.
li_Success = loo_Zip.OpenZip("c:/temp/example.zip")
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    return
end if

// A ZIP archive may contain zero entries.
if loo_Zip.NumEntries = 0 then

    Write-Debug "The ZIP archive is empty."

    loo_Zip.CloseZip()
    destroy loo_Zip
    return
end if

// ------------------------------------------------------------
// Get the first ZIP entry.
// 
// EntryAt(0,entry) initializes the ZipEntry object so that
// it represents the first entry in the ZIP archive.
// 
loo_Entry = create oleobject
li_rc = loo_Entry.ConnectToNewObject("Chilkat.ZipEntry")

li_Success = loo_Zip.EntryAt(0,loo_Entry)
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    destroy loo_Entry
    return
end if

// ------------------------------------------------------------
// Iterate through all ZIP entries.
// 
// GetNext updates the same ZipEntry object so that it
// represents the next entry in the ZIP archive.
// 
do while (li_Success = 1)

    if loo_Entry.IsDirectory = 1 then

        Write-Debug "[Directory] " + loo_Entry.FileName

    else

        Write-Debug "[File] " + loo_Entry.FileName
    end if

    // Advance to the next entry.
    li_Success = loo_Entry.GetNext()
loop

loo_Zip.CloseZip()

Write-Debug "Done."


destroy loo_Zip
destroy loo_Entry