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

Unzip Selected Files from a Zip Archive

See more Zip Examples

Demonstrates how to iterate over the files contained within a .zip and unzip specific files.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let zip = chilkat::Zip::new();

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

let unzip_dir = "/temp/unzipDir".to_string();

// Get the number of files and directories in the .zip
let n = zip.num_entries();

let entry = chilkat::ZipEntry::new();

let mut i = 0;
while i < n {

    let _ = zip.entry_at(i, &entry);
    if !entry.is_directory() {
        // (the filename may include a path)
        println!("{}", entry.file_name());

        // Your application may choose to unzip this entry
        // based on the filename.
        // If the entry should be unzipped, then call Extract(unzipDir)
        if entry.extract(&unzip_dir).is_err() {
            println!("{}", entry.last_error_text());
            return;
        }

    }

    i = i + 1;
}