diff --git a/.gitignore b/.gitignore index ea8c4bf..c44eaa5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target + +_test/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..ac09540 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# unzip-all + +unzip all compressed file using unar. + +first time write rust executable program~ diff --git a/src/main.rs b/src/main.rs index 009c6e9..e705f9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,17 +2,22 @@ use std::fs; use std::io; use std::path::{Path, PathBuf}; use std::process::Command; +use std::env; fn process_compressed_files(path: &Path) -> io::Result<()> { if path.is_dir() { + println!("Path: {}", path.display()); for entry in fs::read_dir(path)? { - let entry_path = entry?.path(); + let entry_path = fs::canonicalize(entry?.path())?; process_compressed_files(&entry_path)?; } } else { - if path.extension() == Some(std::ffi::OsStr::new("rar")) - || path.extension() == Some(std::ffi::OsStr::new("zip")) { + if path.extension().map_or(false, |ext| + ext == "rar" || ext == "zip", + ) { + println!("UNAR: {}", path.display()); let output = Command::new("unar") + .current_dir(path) .arg(path) .output(); @@ -33,7 +38,14 @@ fn process_compressed_files(path: &Path) -> io::Result<()> { } fn main() -> io::Result<()> { - let start_path = PathBuf::from("."); + let args: Vec = env::args().collect(); + + let start_path = if args.len() > 1 { + PathBuf::from(args[1].clone()) + } else { + PathBuf::from(".") + }; process_compressed_files(&start_path)?; + Ok(()) }