PureBasic
PureBasic
Find a ZIP Entry by EntryID Using EntryById
See more Zip Examples
This example demonstrates how to use the EntryById method to retrieve a ZIP entry using its unique EntryID.
Each ZipEntry object has an EntryID property that uniquely identifies the entry within the currently open ZIP object.
This is useful when:
- An application stores EntryID values for later use
- ZIP entries need to be retrieved without searching by filename
- Multiple entries may have similar names or paths
The example:
- Opens a ZIP archive
-
Retrieves an entry using
EntryAt -
Saves the entry's
EntryID -
Uses
EntryByIdto retrieve the same entry later
Chilkat PureBasic Downloads
IncludeFile "CkZip.pb"
IncludeFile "CkZipEntry.pb"
Procedure ChilkatExample()
success.i = 0
success = 0
; Open an existing ZIP archive.
zip.i = CkZip::ckCreate()
If zip.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkZip::ckOpenZip(zip,"example.zip")
If success = 0
Debug CkZip::ckLastErrorText(zip)
CkZip::ckDispose(zip)
ProcedureReturn
EndIf
; Retrieve the first entry in the ZIP archive.
entry.i = CkZipEntry::ckCreate()
If entry.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkZip::ckEntryAt(zip,0,entry)
If success = 0
Debug CkZip::ckLastErrorText(zip)
CkZip::ckDispose(zip)
CkZipEntry::ckDispose(entry)
ProcedureReturn
EndIf
Debug "Original entry:"
Debug " FileName: " + CkZipEntry::ckFileName(entry)
Debug " EntryID: " + Str(CkZipEntry::ckEntryID(entry))
Debug ""
; Save the EntryID for later use.
entryId.i = CkZipEntry::ckEntryID(entry)
; Create another ZipEntry object.
entry2.i = CkZipEntry::ckCreate()
If entry2.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Retrieve the same entry using EntryById.
success = CkZip::ckEntryById(zip,entryId,entry2)
If success = 0
Debug CkZip::ckLastErrorText(zip)
CkZip::ckDispose(zip)
CkZipEntry::ckDispose(entry)
CkZipEntry::ckDispose(entry2)
ProcedureReturn
EndIf
Debug "Entry retrieved by EntryID:"
Debug " FileName: " + CkZipEntry::ckFileName(entry2)
Debug " EntryID: " + Str(CkZipEntry::ckEntryID(entry2))
Debug ""
; The filenames and EntryID values should match.
CkZip::ckCloseZip(zip)
Debug "Done."
CkZip::ckDispose(zip)
CkZipEntry::ckDispose(entry)
CkZipEntry::ckDispose(entry2)
ProcedureReturn
EndProcedure