Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

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

loZip = createobject("CkZip")

// 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
llSuccess = loZip.OpenZip("qa_data/zips/xml_files.zip")
if (llSuccess = .F.) then
    ? loZip.LastErrorText
    release loZip
    return
endif

loSbFilename = createobject("CkStringBuilder")

loEntry = createobject("CkZipEntry")
lnNumEntries = loZip.NumEntries
i = 0
do while i < lnNumEntries
    loZip.EntryAt(i,loEntry)

    lcEntryFilePath = loEntry.FileName
    ? lcEntryFilePath

    if (loEntry.IsDirectory = .F.) then
        loSbFilename.SetString(lcEntryFilePath)
        if (loSbFilename.Contains("/",.F.) = .F.) then
            // Does not contain "/"
            // Unzip to the qa_output directory.
            llSuccess = loEntry.Extract("qa_output")
            if (llSuccess = .F.) then
                ? "Failed to unzip " + lcEntryFilePath
            else
                ? "Unzipped " + lcEntryFilePath
            endif

        endif

    endif

    i = i + 1
enddo


release loZip
release loSbFilename
release loEntry