Sample code for 30+ languages & platforms
Rust

Zip -- Exclude Files Based on Wildcard Matching

See more Zip Examples

Demonstrates how to use the SetExclusions method to exclude matching files from being added to a .zip.

Chilkat Rust Downloads

Rust

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

let _ = zip.new_zip("qa_output/x.zip").is_ok();

// Let's add files from the directory tree rooted at C:\AAWorkarea\ChilkatSampleProjects

// However.. we want to exclude all files ending in ".cache" or ".pdb" regardless of the sub-directory.
// Also exclude all files under any "obj" directory,
// and we also want to exclude any .exe found under a "win10-x64" directory.

let sa_excludes = chilkat::StringArray::new();
let _ = sa_excludes.append("*.cache");
let _ = sa_excludes.append("*.pdb");
let _ = sa_excludes.append("*/obj/*");
let _ = sa_excludes.append("*/win10-x64/*.exe");
zip.set_exclusions(&sa_excludes);

// Append promises of paths and files to be zipped.
let recurse = true;
if zip.append_files("c:/AAWorkArea/ChilkatSampleProjects/*", recurse).is_err() {
    println!("{}", zip.last_error_text());
    return;
}

// Create the zip from the file and directory promises added previously.
if zip.write_zip_and_close().is_err() {
    println!("{}", zip.last_error_text());
    return;
}

println!("Success.");