Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oZip
LOCAL cZipPath
LOCAL nRecurse
LOCAL nNumEntries
LOCAL oEntry
LOCAL i

nSuccess := 0

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

oZip := CreateObject("Chilkat.Zip")

cZipPath := "c:/temp/myFiles.zip"

//  Initialize the zip object, which also sets the FileName property to the path of the zip to be created.
oZip:NewZip(cZipPath)

//  Append references to files to be zipped.
nRecurse := 1
nSuccess := oZip:AppendFiles("c:/temp/files_to_zip/*", nRecurse)
IF (nSuccess == 0)
    ? oZip:LastErrorText
    oZip:destroy()
    RETURN
ENDIF

//  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)
nSuccess := oZip:WriteZip()
IF (nSuccess == 0)
    ? oZip:LastErrorText
    oZip:destroy()
    RETURN
ENDIF

? "Successfully created " + cZipPath

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

nNumEntries := oZip:NumEntries

oEntry := CreateObject("Chilkat.ZipEntry")

i := 0
DO WHILE i < nNumEntries
    oZip:EntryAt(i, oEntry)
    IF (oEntry:IsDirectory)
        ? Str(i) + ": " + oEntry:FileName + " (directory)"
    ELSE
        ? Str(i) + ": " + oEntry:FileName
    ENDIF

    i := i + 1
ENDDO

//  Close the zip file when finished.
oZip:CloseZip()

oZip:destroy()
oEntry:destroy()