Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loZip
LOCAL lcCharset
LOCAL loZip2
LOCAL loEntry
lnSuccess = 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..
loZip = CreateObject('Chilkat.Zip')
loZip.NewZip("qa_output/abc.zip")
* Add some files..
lcCharset = "utf-8"
loZip.AddString("a.txt","aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",lcCharset)
loZip.AddString("b.txt","bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",lcCharset)
loZip.AddString("c.txt","cccccccccccccccccccccccccccccccccccc",lcCharset)
* Write to qa_output/abc.zip
* This .zip contains three files: a.txt, b.txt, and c.txt
lnSuccess = loZip.WriteZipAndClose()
* -------------------------------------------------------------------
* Open abc.zip, replace the content of the "b.txt" entry with something else, and re-write.
loZip2 = CreateObject('Chilkat.Zip')
loZip2.OpenZip("qa_output/abc.zip")
loEntry = CreateObject('Chilkat.ZipEntry')
IF (loZip2.EntryOf("b.txt",loEntry) = 1) THEN
loEntry.ReplaceString("This is the new content. bbbbbbbbbbbbbbbbbbbbbb","utf-8")
ENDIF
* Write the modified .zip back to "abc.zip"
lnSuccess = loZip2.WriteZipAndClose()
? "success."
RELEASE loZip
RELEASE loZip2
RELEASE loEntry