judge is_dir first.
This commit is contained in:
parent
3edc4369f4
commit
a99523f4e6
50
src/main.rs
50
src/main.rs
@ -5,33 +5,35 @@ use std::process::Command;
|
||||
use std::env;
|
||||
|
||||
fn process_compressed_files(path: &Path) -> io::Result<()> {
|
||||
if path.is_dir() {
|
||||
println!("Processing directory: {}", path.display());
|
||||
for entry in fs::read_dir(path)? {
|
||||
let entry_path = entry?.path();
|
||||
if entry_path.is_dir() {
|
||||
process_compressed_files(&entry_path)?;
|
||||
} else if let Some(ext) = entry_path.extension().and_then(|e| e.to_str()) {
|
||||
if ext == "rar" || ext == "zip" {
|
||||
println!("UNAR: {}", entry_path.display());
|
||||
let parent_dir = entry_path.parent().unwrap();
|
||||
let filename = entry_path.file_name().expect("WRONG.").to_str().unwrap();
|
||||
let output = Command::new("unar")
|
||||
.current_dir(parent_dir)
|
||||
.arg(filename)
|
||||
.output();
|
||||
if !path.is_dir() {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Not a directory"));
|
||||
}
|
||||
|
||||
match output {
|
||||
Ok(result) => {
|
||||
if !result.status.success() {
|
||||
eprintln!("Error processing compressed file {:?}: {}", entry_path, String::from_utf8_lossy(&result.stderr));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to execute unar for {:?}: {}", entry_path, e);
|
||||
return Err(e);
|
||||
println!("Processing directory: {}", path.display());
|
||||
for entry in fs::read_dir(path)? {
|
||||
let entry_path = entry?.path();
|
||||
if entry_path.is_dir() {
|
||||
process_compressed_files(&entry_path)?;
|
||||
} else if let Some(ext) = entry_path.extension().and_then(|e| e.to_str()) {
|
||||
if ext == "rar" || ext == "zip" {
|
||||
println!("UNAR: {}", entry_path.display());
|
||||
let parent_dir = entry_path.parent().unwrap();
|
||||
let filename = entry_path.file_name().expect("WRONG.").to_str().unwrap();
|
||||
let output = Command::new("unar")
|
||||
.current_dir(parent_dir)
|
||||
.arg(filename)
|
||||
.output();
|
||||
|
||||
match output {
|
||||
Ok(result) => {
|
||||
if !result.status.success() {
|
||||
eprintln!("Error processing compressed file {:?}: {}", entry_path, String::from_utf8_lossy(&result.stderr));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to execute unar for {:?}: {}", entry_path, e);
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user