Sample code for 30+ languages & platforms
DataFlex

Zip a Directory Tree

See more Zip Examples

Demonstrates how to zip an entire directory tree into a .zip archive.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoZip
    Boolean iRecurse
    String sTemp1

    Move False To iSuccess

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

    Get ComNewZip Of hoZip "test.zip" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoZip To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Append a directory tree.  The call to AppendFiles does
    // not read the file contents or append them to the zip
    // object in memory.  It simply appends references
    // to the files so that when WriteZip or WriteZipAndClose 
    // is called, the referenced files are streamed and compressed
    // into the .zip output file.

    Move True To iRecurse
    Get ComAppendFiles Of hoZip "c:/temp/a/*" iRecurse To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoZip To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComWriteZipAndClose Of hoZip To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoZip To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Zip Created!"


End_Procedure