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

Unzip Some Files by Iterating over Entries

See more Zip Examples

Demonstrates how to unzip specific files by iterating over entries in a .zip.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oZip
LOCAL oSbFilename
LOCAL oEntry
LOCAL nNumEntries
LOCAL i
LOCAL cEntryFilePath

nSuccess := 0

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

oZip := CreateObject("Chilkat.Zip")

//  Open a .zip containing:
//  
//  a1.xml
//  b1.xml
//  c1.xml
//  dir1/a2.xml
//  dir1/c2.xml
//  dir2/dir3/c3.xml

//  We wish to unzip only a1.xml, b1.xml, and c1.xml
nSuccess := oZip:OpenZip("qa_data/zips/xml_files.zip")
IF (nSuccess == 0)
    ? oZip:LastErrorText
    oZip:destroy()
    RETURN
ENDIF

oSbFilename := CreateObject("Chilkat.StringBuilder")

oEntry := CreateObject("Chilkat.ZipEntry")
nNumEntries := oZip:NumEntries
i := 0
DO WHILE i < nNumEntries
    oZip:EntryAt(i, oEntry)

    cEntryFilePath := oEntry:FileName
    ? cEntryFilePath

    IF (oEntry:IsDirectory == 0)
        oSbFilename:SetString(cEntryFilePath)
        IF (oSbFilename:Contains("/", 0) == 0)
            //  Does not contain "/"
            //  Unzip to the qa_output directory.
            nSuccess := oEntry:Extract("qa_output")
            IF (nSuccess == 0)
                ? "Failed to unzip " + cEntryFilePath
            ELSE
                ? "Unzipped " + cEntryFilePath
            ENDIF

        ENDIF

    ENDIF

    i := i + 1
ENDDO

oZip:destroy()
oSbFilename:destroy()
oEntry:destroy()