Sample code for 30+ languages & platforms
Tcl

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 EntryById to retrieve the same entry later

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set success 0

# Open an existing ZIP archive.
set zip [new_CkZip]

set success [CkZip_OpenZip $zip "example.zip"]
if {$success == 0} then {
    puts [CkZip_lastErrorText $zip]
    delete_CkZip $zip
    exit
}

# Retrieve the first entry in the ZIP archive.
set entry [new_CkZipEntry]

set success [CkZip_EntryAt $zip 0 $entry]
if {$success == 0} then {
    puts [CkZip_lastErrorText $zip]
    delete_CkZip $zip
    delete_CkZipEntry $entry
    exit
}

puts "Original entry:"
puts "  FileName: [CkZipEntry_fileName $entry]"
puts "  EntryID: [CkZipEntry_get_EntryID $entry]"
puts 

# Save the EntryID for later use.
set entryId [CkZipEntry_get_EntryID $entry]

# Create another ZipEntry object.
set entry2 [new_CkZipEntry]

# Retrieve the same entry using EntryById.
set success [CkZip_EntryById $zip $entryId $entry2]
if {$success == 0} then {
    puts [CkZip_lastErrorText $zip]
    delete_CkZip $zip
    delete_CkZipEntry $entry
    delete_CkZipEntry $entry2
    exit
}

puts "Entry retrieved by EntryID:"
puts "  FileName: [CkZipEntry_fileName $entry2]"
puts "  EntryID: [CkZipEntry_get_EntryID $entry2]"
puts 

# The filenames and EntryID values should match.
CkZip_CloseZip $zip

puts "Done."

delete_CkZip $zip
delete_CkZipEntry $entry
delete_CkZipEntry $entry2