add user-friendly info.
This commit is contained in:
parent
7731c177c9
commit
c870b16634
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
/target
|
||||
|
||||
_test/
|
||||
|
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# unzip-all
|
||||
|
||||
unzip all compressed file using unar.
|
||||
|
||||
first time write rust executable program~
|
20
src/main.rs
20
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<String> = env::args().collect();
|
||||
|
||||
let start_path = if args.len() > 1 {
|
||||
PathBuf::from(args[1].clone())
|
||||
} else {
|
||||
PathBuf::from(".")
|
||||
};
|
||||
process_compressed_files(&start_path)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user