Sample code for 30+ languages & platforms
PowerBuilder

Iterate over Matching Filenames

See more Zip Examples

Iterates over files within a .zip that match a pattern. In this case, the pattern is "*.pem". This example will open a .zip containing files of type .txt, .cer, .pem, and possibly others, and will iterate over only the .pem files.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Zip
oleobject loo_Entry
string ls_PemStr
string ls_Pattern
integer li_BHasMoreMatches

li_Success = 0

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

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 a .zip containing PEM files, among other things..
li_Success = loo_Zip.OpenZip("qa_data/certs/thawte-roots.zip")
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    return
end if

loo_Entry = create oleobject
li_rc = loo_Entry.ConnectToNewObject("Chilkat.ZipEntry")

ls_Pattern = "*.pem"

li_BHasMoreMatches = loo_Zip.EntryMatching(ls_Pattern,loo_Entry)
do while li_BHasMoreMatches = 1

    Write-Debug "Entry: " + loo_Entry.FileName

    // Get the uncommpressed contents of the entry:
    ls_PemStr = loo_Entry.UnzipToString(0,"utf-8")
    Write-Debug ls_PemStr

    li_BHasMoreMatches = loo_Entry.GetNextMatch(ls_Pattern)
loop


destroy loo_Zip
destroy loo_Entry