Rust Requires Chilkat v11.0.0+
Rust
Unzip Some Files by Iterating over Entries
See more Zip Examples
Demonstrates how to unzip specific files by iterating over entries in a .zip.Chilkat Rust Downloads
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let zip = chilkat::Zip::new();
// Open a .zip containing:
//
// a1.xml
// b1.xml
// c1.xml
// dir1/a2.xml
// dir1/c2.xml
// dir2/dir3/c3.xml
// We wish to unzip only a1.xml, b1.xml, and c1.xml
if zip.open_zip("qa_data/zips/xml_files.zip").is_err() {
println!("{}", zip.last_error_text());
return;
}
let sb_filename = chilkat::StringBuilder::new();
let entry = chilkat::ZipEntry::new();
let num_entries = zip.num_entries();
let mut i = 0;
while i < num_entries {
let _ = zip.entry_at(i, &entry);
let entry_file_path = entry.file_name();
println!("{}", entry_file_path);
if !entry.is_directory() {
let _ = sb_filename.set_string(&entry_file_path);
if !sb_filename.contains("/", false) {
// Does not contain "/"
// Unzip to the qa_output directory.
if entry.extract("qa_output").is_err() {
println!("Failed to unzip {}", entry_file_path);
} else {
println!("Unzipped {}", entry_file_path);
}
}
}
i = i + 1;
}