Sample code for 30+ languages & platforms
DataFlex

Zip and Keep Open

See more Zip Examples

Zip a directory tree by calling WriteZip instead of WriteZipAndClose. When WriteZip is called, the created zip is automatically opened and the zip object contains references to the compressed zip entries (mapped entries) contained within the .zip.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoZip
    String sZipPath
    Boolean iRecurse
    Integer iNumEntries
    Variant vEntry
    Handle hoEntry
    Integer i
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    // This example assumes 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

    Move "c:/temp/myFiles.zip" To sZipPath

    // Initialize the zip object, which also sets the FileName property to the path of the zip to be created.
    Get ComNewZip Of hoZip sZipPath To iSuccess

    // Append references to files to be zipped.
    Move True To iRecurse
    Get ComAppendFiles Of hoZip "c:/temp/files_to_zip/*" iRecurse To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoZip To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Write the .zip, but don't close the zip file.
    // The zip file we just created is automatically opened and the zip object
    // now contains entries that are contained within the zip.  (They are memory-mapped entries)
    Get ComWriteZip Of hoZip To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoZip To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Successfully created " sZipPath

    // Let's look at what's in the .zip we just created..

    Get ComNumEntries Of hoZip To iNumEntries

    Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
    If (Not(IsComObjectCreated(hoEntry))) Begin
        Send CreateComObject of hoEntry
    End

    Move 0 To i
    While (i < iNumEntries)
        Get pvComObject of hoEntry to vEntry
        Get ComEntryAt Of hoZip i vEntry To iSuccess
        Get ComIsDirectory Of hoEntry To bTemp1
        If (bTemp1) Begin
            Get ComFileName Of hoEntry To sTemp1
            Showln i ": " sTemp1 " (directory)"
        End
        Else Begin
            Get ComFileName Of hoEntry To sTemp1
            Showln i ": " sTemp1
        End

        Move (i + 1) To i
    Loop

    // Close the zip file when finished.
    Send ComCloseZip To hoZip


End_Procedure