use std::fs::File; use std::env; use std::io::{Read, Write}; use zip::{read::ZipArchive, write::FileOptions}; fn unzip_file(zip_path: &str, output_path: &str) -> Result<(), Box<dyn std::error::Error>> { // Open the ZIP file let file = File::open(zip_path)?; let mut archive = ZipArchive::new(file)?; // Iterate through each file in the ZIP archive for i in 0..archive.len() { let mut file = archive.by_index(i)?; let output_file_path = format!("{}/{}", output_path, file.name()); if let Some(parent) = std::path::Path::new(&output_file_path).parent() { std::fs::create_dir_all(parent)?; } if file.is_dir() { std::fs::create_dir_all(output_file_path); } else { let mut output_file = File::create(output_file_path)?; std::io::copy(&mut file, &mut output_file)?; } } Ok(()) } fn unzip_1(arg: String) { let output_path = "zipout"; match unzip_file(&arg, &output_path) { Ok(()) => println!("Unzip of {} successful", &arg), Err(err) => eprintln!("Error with {}: {}", &arg, err) } } fn main() { let args: Vec<String> = env::args().collect(); for arg in args { unzip_1(arg); } }