C Requires Chilkat v11.0.0+
C
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 C Downloads
#include <C_CkZip.h>
#include <C_CkZipEntry.h>
void ChilkatSample(void)
{
BOOL success;
HCkZip zip;
HCkZipEntry entry;
int entryId;
HCkZipEntry entry2;
success = FALSE;
// Open an existing ZIP archive.
zip = CkZip_Create();
success = CkZip_OpenZip(zip,"example.zip");
if (success == FALSE) {
printf("%s\n",CkZip_lastErrorText(zip));
CkZip_Dispose(zip);
return;
}
// Retrieve the first entry in the ZIP archive.
entry = CkZipEntry_Create();
success = CkZip_EntryAt(zip,0,entry);
if (success == FALSE) {
printf("%s\n",CkZip_lastErrorText(zip));
CkZip_Dispose(zip);
CkZipEntry_Dispose(entry);
return;
}
printf("Original entry:\n");
printf(" FileName: %s\n",CkZipEntry_fileName(entry));
printf(" EntryID: %d\n",CkZipEntry_getEntryID(entry));
printf("\n");
// Save the EntryID for later use.
entryId = CkZipEntry_getEntryID(entry);
// Create another ZipEntry object.
entry2 = CkZipEntry_Create();
// Retrieve the same entry using EntryById.
success = CkZip_EntryById(zip,entryId,entry2);
if (success == FALSE) {
printf("%s\n",CkZip_lastErrorText(zip));
CkZip_Dispose(zip);
CkZipEntry_Dispose(entry);
CkZipEntry_Dispose(entry2);
return;
}
printf("Entry retrieved by EntryID:\n");
printf(" FileName: %s\n",CkZipEntry_fileName(entry2));
printf(" EntryID: %d\n",CkZipEntry_getEntryID(entry2));
printf("\n");
// The filenames and EntryID values should match.
CkZip_CloseZip(zip);
printf("Done.\n");
CkZip_Dispose(zip);
CkZipEntry_Dispose(entry);
CkZipEntry_Dispose(entry2);
}