Unicode C
Unicode C
Iterate Over ZIP Entries Using EntryAt
This example demonstrates how to use the EntryAt method to iterate over all entries contained within a ZIP archive.
The EntryAt method retrieves a ZipEntry object for a given zero-based index.
This is useful for:
- Enumerating all entries in a ZIP archive
- Inspecting filenames, sizes, and timestamps
- Searching or filtering ZIP contents
Suppose the ZIP archive contains:
docs/readme.txt
images/logo.png
data/config.json The example loops through all ZIP entries and prints information about each entry.
Chilkat Unicode C Downloads
#include <C_CkZipW.h>
#include <C_CkZipEntryW.h>
void ChilkatSample(void)
{
BOOL success;
HCkZipW zip;
int numEntries;
HCkZipEntryW entry;
int i;
success = FALSE;
success = FALSE;
// Open an existing ZIP archive.
zip = CkZipW_Create();
success = CkZipW_OpenZip(zip,L"example.zip");
if (success == FALSE) {
wprintf(L"%s\n",CkZipW_lastErrorText(zip));
CkZipW_Dispose(zip);
return;
}
// Get the total number of entries in the ZIP archive.
numEntries = CkZipW_getNumEntries(zip);
wprintf(L"Number of ZIP entries = %d\n",numEntries);
// Create a ZipEntry object that will be reused
// for each entry retrieved by EntryAt.
entry = CkZipEntryW_Create();
// Iterate over all ZIP entries.
i = 0;
while (i < numEntries) {
// Retrieve the entry at index i.
success = CkZipW_EntryAt(zip,i,entry);
if (success == FALSE) {
wprintf(L"%s\n",CkZipW_lastErrorText(zip));
CkZipW_Dispose(zip);
CkZipEntryW_Dispose(entry);
return;
}
wprintf(L"Entry %d\n",i);
wprintf(L" FileName: %s\n",CkZipEntryW_fileName(entry));
wprintf(L" Uncompressed Length: %u\n",CkZipEntryW_getUncompressedLength(entry));
wprintf(L" Compressed Length: %u\n",CkZipEntryW_getCompressedLength(entry));
wprintf(L"\n");
i = i + 1;
}
// Sample output:
//
// Entry 0
// FileName: docs/readme.txt
// Uncompressed Length: 1204
// Compressed Length: 512
//
// Entry 1
// FileName: images/logo.png
// Uncompressed Length: 84211
// Compressed Length: 84102
//
CkZipW_CloseZip(zip);
wprintf(L"Done.\n");
CkZipW_Dispose(zip);
CkZipEntryW_Dispose(entry);
}