Visual FoxPro
Visual FoxPro
Unzip Some Files by Iterating over Entries
See more Zip Examples
Demonstrates how to unzip specific files by iterating over entries in a .zip.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loZip
LOCAL loSbFilename
LOCAL loEntry
LOCAL lnNumEntries
LOCAL i
LOCAL lcEntryFilePath
lnSuccess = 0
* This requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loZip = CreateObject('Chilkat.Zip')
* Open a .zip containing:
*
* a1.xml
* b1.xml
* c1.xml
* dir1/a2.xml
* dir1/c2.xml
* dir2/dir3/c3.xml
* We wish to unzip only a1.xml, b1.xml, and c1.xml
lnSuccess = loZip.OpenZip("qa_data/zips/xml_files.zip")
IF (lnSuccess = 0) THEN
? loZip.LastErrorText
RELEASE loZip
CANCEL
ENDIF
loSbFilename = CreateObject('Chilkat.StringBuilder')
loEntry = CreateObject('Chilkat.ZipEntry')
lnNumEntries = loZip.NumEntries
i = 0
DO WHILE i < lnNumEntries
loZip.EntryAt(i,loEntry)
lcEntryFilePath = loEntry.FileName
? lcEntryFilePath
IF (loEntry.IsDirectory = 0) THEN
loSbFilename.SetString(lcEntryFilePath)
IF (loSbFilename.Contains("/",0) = 0) THEN
* Does not contain "/"
* Unzip to the qa_output directory.
lnSuccess = loEntry.Extract("qa_output")
IF (lnSuccess = 0) THEN
? "Failed to unzip " + lcEntryFilePath
ELSE
? "Unzipped " + lcEntryFilePath
ENDIF
ENDIF
ENDIF
i = i + 1
ENDDO
RELEASE loZip
RELEASE loSbFilename
RELEASE loEntry