add user-friendly info.

This commit is contained in:
licsber 2024-09-08 00:09:11 +08:00
parent 7731c177c9
commit c870b16634
3 changed files with 23 additions and 4 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
/target /target
_test/

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# unzip-all
unzip all compressed file using unar.
first time write rust executable program~

View File

@ -2,17 +2,22 @@ use std::fs;
use std::io; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use std::env;
fn process_compressed_files(path: &Path) -> io::Result<()> { fn process_compressed_files(path: &Path) -> io::Result<()> {
if path.is_dir() { if path.is_dir() {
println!("Path: {}", path.display());
for entry in fs::read_dir(path)? { for entry in fs::read_dir(path)? {
let entry_path = entry?.path(); let entry_path = fs::canonicalize(entry?.path())?;
process_compressed_files(&entry_path)?; process_compressed_files(&entry_path)?;
} }
} else { } else {
if path.extension() == Some(std::ffi::OsStr::new("rar")) if path.extension().map_or(false, |ext|
|| path.extension() == Some(std::ffi::OsStr::new("zip")) { ext == "rar" || ext == "zip",
) {
println!("UNAR: {}", path.display());
let output = Command::new("unar") let output = Command::new("unar")
.current_dir(path)
.arg(path) .arg(path)
.output(); .output();
@ -33,7 +38,14 @@ fn process_compressed_files(path: &Path) -> io::Result<()> {
} }
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
let start_path = PathBuf::from("."); let args: Vec<String> = env::args().collect();
let start_path = if args.len() > 1 {
PathBuf::from(args[1].clone())
} else {
PathBuf::from(".")
};
process_compressed_files(&start_path)?; process_compressed_files(&start_path)?;
Ok(()) Ok(())
} }