DataFlex
DataFlex
Iterate Through Matching ZIP Entries Using EntryMatching and ZipEntry.GetNextMatch
See more Zip Examples
This example demonstrates how to iterate through ZIP entries matching a wildcard pattern using:
-
Zip.EntryMatchingto obtain the first matching entry -
ZipEntry.GetNextMatchto advance to subsequent matching entries
The wildcard character * matches zero or more characters. Matching is performed against the full stored ZIP entry path.
The example searches for all entries beneath the docs/ directory.
Suppose the ZIP archive contains:
docs/
docs/readme.txt
docs/manual.pdf
docs/sub1/notes.txt
images/logo.png
hello.txt The wildcard pattern:
docs/* Matches:
docs/
docs/readme.txt
docs/manual.pdf
docs/sub1/notes.txt Note that ZIP archives may optionally contain separate directory entries. Therefore, the first matching entry may be the directory entry docs/ rather than a file entry.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoZip
Variant vEntry
Handle hoEntry
String sTemp1
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/sample.zip" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
// ------------------------------------------------------------
// Find the first ZIP entry matching the wildcard pattern:
//
// docs/*
//
// Matching is performed against the full stored ZIP path.
//
Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
If (Not(IsComObjectCreated(hoEntry))) Begin
Send CreateComObject of hoEntry
End
Get pvComObject of hoEntry to vEntry
Get ComEntryMatching Of hoZip "docs/*" vEntry To iSuccess
If (iSuccess = False) Begin
Showln "No matching entries found."
Send ComCloseZip To hoZip
Procedure_Return
End
// ------------------------------------------------------------
// Iterate through all matching entries.
//
// GetNextMatch updates the same ZipEntry object so that
// it represents the next matching entry.
//
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 matching entry.
Get ComGetNextMatch Of hoEntry "docs/*" To iSuccess
Loop
Send ComCloseZip To hoZip
Showln "Done."
End_Procedure