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

Change a Filename before Unzipping

See more Zip Examples

How to open a zip and modify the filename of one or more files within the zip before unzipping.

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("test.zip").is_err() {
    println!("{}", zip.last_error_text());
    return;
}

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

if zip.entry_of("hamlet.xml", &entry).is_err() {
    println!("{}", zip.last_error_text());
    return;
}

entry.set_file_name("hamlet2.xml");

if zip.entry_of("helloWorld.pl", &entry).is_err() {
    println!("{}", zip.last_error_text());
    return;
}

entry.set_file_name("hw.pl");

// Now unzip to the "test" subdirectory, under our current
// working directory:
let num_files_unzipped = zip.unzip("test");
if num_files_unzipped < 0 {
    println!("{}", zip.last_error_text());
    return;
}

// The filenames within the .zip are unchanged, but it unzipped
// test/hw.pl and test/hamlet2.xml