DataFlex
DataFlex
Iterate Through ZIP Entries Using EntryAt and ZipEntry.GetNext
See more Zip Examples
This example demonstrates how to iterate through all entries in a ZIP archive using:
-
Zip.EntryAtto obtain the first entry -
ZipEntry.GetNextto advance through the remaining entries
The example prints each ZIP entry's stored filename and whether the entry is a file or directory.
This approach is useful when sequentially processing ZIP entries without repeatedly calling EntryAt by index.
Suppose the ZIP archive contains:
docs/
docs/readme.txt
images/logo.png
hello.txt The example iterates through each entry in the order stored within the ZIP archive.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoZip
Variant vEntry
Handle hoEntry
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatZip)) To hoZip
If (Not(IsComObjectCreated(hoZip))) Begin
Send CreateComObject of hoZip
End
// Open an existing ZIP archive.
Get ComOpenZip Of hoZip "c:/temp/example.zip" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
// A ZIP archive may contain zero entries.
Get ComNumEntries Of hoZip To iTemp1
If (iTemp1 = 0) Begin
Showln "The ZIP archive is empty."
Send ComCloseZip To hoZip
Procedure_Return
End
// ------------------------------------------------------------
// Get the first ZIP entry.
//
// EntryAt(0,entry) initializes the ZipEntry object so that
// it represents the first entry in the ZIP archive.
//
Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
If (Not(IsComObjectCreated(hoEntry))) Begin
Send CreateComObject of hoEntry
End
Get pvComObject of hoEntry to vEntry
Get ComEntryAt Of hoZip 0 vEntry To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
// ------------------------------------------------------------
// Iterate through all ZIP entries.
//
// GetNext updates the same ZipEntry object so that it
// represents the next entry in the ZIP archive.
//
While (iSuccess = True)
Get ComIsDirectory Of hoEntry To bTemp1
If (bTemp1 = True) Begin
Get ComFileName Of hoEntry To sTemp1
Showln "[Directory] " sTemp1
End
Else Begin
Get ComFileName Of hoEntry To sTemp1
Showln "[File] " sTemp1
End
// Advance to the next entry.
Get ComGetNext Of hoEntry To iSuccess
Loop
Send ComCloseZip To hoZip
Showln "Done."
End_Procedure