Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

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 Rust Downloads

Rust

// Open an existing ZIP archive.
let zip = chilkat::Zip::new();

if zip.open_zip("example.zip").is_err() {
    println!("{}", zip.last_error_text());
    return;
}

// Get the total number of entries in the ZIP archive.
let num_entries = zip.num_entries();

println!("Number of ZIP entries = {}", num_entries);

// Create a ZipEntry object that will be reused
// for each entry retrieved by EntryAt.
let entry = chilkat::ZipEntry::new();

// Iterate over all ZIP entries.
let mut i = 0;
while i < num_entries {

    // Retrieve the entry at index i.
    if zip.entry_at(i, &entry).is_err() {
        println!("{}", zip.last_error_text());
        return;
    }

    println!("Entry {}", i);
    println!("  FileName: {}", entry.file_name());
    println!("  Uncompressed Length: {}", entry.uncompressed_length());
    println!("  Compressed Length: {}", entry.compressed_length());
    println!("");

    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
// 

zip.close_zip();

println!("Done.");