Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoZip
    Handle hoSbFilename
    Variant vEntry
    Handle hoEntry
    Integer iNumEntries
    Integer i
    String sEntryFilePath
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatZip)) To hoZip
    If (Not(IsComObjectCreated(hoZip))) Begin
        Send CreateComObject of hoZip
    End

    // 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
    Get ComOpenZip Of hoZip "qa_data/zips/xml_files.zip" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoZip To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbFilename
    If (Not(IsComObjectCreated(hoSbFilename))) Begin
        Send CreateComObject of hoSbFilename
    End

    Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
    If (Not(IsComObjectCreated(hoEntry))) Begin
        Send CreateComObject of hoEntry
    End
    Get ComNumEntries Of hoZip To iNumEntries
    Move 0 To i
    While (i < iNumEntries)
        Get pvComObject of hoEntry to vEntry
        Get ComEntryAt Of hoZip i vEntry To iSuccess

        Get ComFileName Of hoEntry To sEntryFilePath
        Showln sEntryFilePath

        Get ComIsDirectory Of hoEntry To bTemp1
        If (bTemp1 = False) Begin
            Get ComSetString Of hoSbFilename sEntryFilePath To iSuccess
            Get ComContains Of hoSbFilename "/" False To bTemp1
            If (bTemp1 = False) Begin
                // Does not contain "/"
                // Unzip to the qa_output directory.
                Get ComExtract Of hoEntry "qa_output" To iSuccess
                If (iSuccess = False) Begin
                    Showln "Failed to unzip " sEntryFilePath
                End
                Else Begin
                    Showln "Unzipped " sEntryFilePath
                End

            End

        End

        Move (i + 1) To i
    Loop



End_Procedure