Sample code for 30+ languages & platforms
PureBasic

Append String as a File to a Zip

See more Zip Examples

Demonstrates how to append text data as a file within a zip archive.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkZip.pb"

Procedure ChilkatExample()

    success.i = 0

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

    zip.i = CkZip::ckCreate()
    If zip.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    zipPath.s = "c:/temp/test.zip"

    ; Initialize the zip object, which also sets the FileName property to the path of the zip to be created.
    CkZip::ckNewZip(zip,zipPath)

    ; Append a file that will contain the string "Hello World";
    fileContent.s = "Hello World"
    pathInZip.s = "txtFiles/helloWorld.txt"
    CkZip::ckAddString(zip,pathInZip,fileContent,"utf-8")

    CkZip::setCkFileName(zip, zipPath)
    success = CkZip::ckWriteZipAndClose(zip)
    If success = 0
        Debug CkZip::ckLastErrorText(zip)
        CkZip::ckDispose(zip)
        ProcedureReturn
    EndIf

    Debug "Success."


    CkZip::ckDispose(zip)


    ProcedureReturn
EndProcedure