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

Unzip Selected Files from a Zip Archive

See more Zip Examples

Demonstrates how to iterate over the files contained within a .zip and unzip specific files.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oZip
LOCAL cUnzipDir
LOCAL n
LOCAL oEntry
LOCAL i

nSuccess := 0

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

oZip := CreateObject("Chilkat.Zip")

nSuccess := oZip:OpenZip("my_files.zip")
IF (nSuccess == 0)
    ? oZip:LastErrorText
    oZip:destroy()
    RETURN
ENDIF

cUnzipDir := "/temp/unzipDir"

//  Get the number of files and directories in the .zip
n := oZip:NumEntries

oEntry := CreateObject("Chilkat.ZipEntry")

i := 0
DO WHILE i < n

    oZip:EntryAt(i, oEntry)
    IF (oEntry:IsDirectory == 0)
        //  (the filename may include a path)
        ? oEntry:FileName

        //  Your application may choose to unzip this entry
        //  based on the filename.
        //  If the entry should be unzipped, then call Extract(unzipDir)
        nSuccess := oEntry:Extract(cUnzipDir)
        IF (nSuccess == 0)
            ? oEntry:LastErrorText
            oZip:destroy()
            oEntry:destroy()
            RETURN
        ENDIF

    ENDIF

    i := i + 1
ENDDO

oZip:destroy()
oEntry:destroy()