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

Replace/Update a FIle in a .zip

See more Zip Examples

Demonstrates how to replace/update a file from a .zip. Note: This requires the entire .zip to be rewritten.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oZip
LOCAL cCharset
LOCAL oZip2
LOCAL oEntry

nSuccess := 0

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

//  First prepare a .zip and write it..
oZip := CreateObject("Chilkat.Zip")

oZip:NewZip("qa_output/abc.zip")

//  Add some files..
cCharset := "utf-8"
oZip:AddString("a.txt", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", cCharset)
oZip:AddString("b.txt", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", cCharset)
oZip:AddString("c.txt", "cccccccccccccccccccccccccccccccccccc", cCharset)

//  Write to qa_output/abc.zip
//  This .zip contains three files: a.txt, b.txt, and c.txt
nSuccess := oZip:WriteZipAndClose()

//  -------------------------------------------------------------------
//  Open abc.zip, replace the content of the "b.txt" entry with something else, and re-write.
oZip2 := CreateObject("Chilkat.Zip")
oZip2:OpenZip("qa_output/abc.zip")

oEntry := CreateObject("Chilkat.ZipEntry")
IF (oZip2:EntryOf("b.txt", oEntry) == 1)
    oEntry:ReplaceString("This is the new content.  bbbbbbbbbbbbbbbbbbbbbb", "utf-8")
ENDIF

//  Write the modified .zip back to "abc.zip"
nSuccess := oZip2:WriteZipAndClose()

? "success."

oZip:destroy()
oZip2:destroy()
oEntry:destroy()