using parent dir as pwd.
This commit is contained in:
parent
c870b16634
commit
5c4a6b6bf1
28
src/main.rs
28
src/main.rs
@ -6,29 +6,32 @@ use std::env;
|
||||
|
||||
fn process_compressed_files(path: &Path) -> io::Result<()> {
|
||||
if path.is_dir() {
|
||||
println!("Path: {}", path.display());
|
||||
println!("Processing directory: {}", path.display());
|
||||
for entry in fs::read_dir(path)? {
|
||||
let entry_path = fs::canonicalize(entry?.path())?;
|
||||
let entry_path = entry?.path();
|
||||
if entry_path.is_dir() {
|
||||
process_compressed_files(&entry_path)?;
|
||||
}
|
||||
} else {
|
||||
if path.extension().map_or(false, |ext|
|
||||
ext == "rar" || ext == "zip",
|
||||
) {
|
||||
println!("UNAR: {}", path.display());
|
||||
} 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().to_str().unwrap();
|
||||
let output = Command::new("unar")
|
||||
.current_dir(path)
|
||||
.arg(path)
|
||||
.current_dir(parent_dir)
|
||||
.arg(filename)
|
||||
.output();
|
||||
|
||||
match output {
|
||||
Ok(result) => {
|
||||
if !result.status.success() {
|
||||
eprintln!("Error processing compressed file {:?}: {}", path, String::from_utf8_lossy(&result.stderr));
|
||||
eprintln!("Error processing compressed file {:?}: {}", entry_path, String::from_utf8_lossy(&result.stderr));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to execute unar for {:?}: {}", path, e);
|
||||
eprintln!("Failed to execute unar for {:?}: {}", entry_path, e);
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,6 +48,7 @@ fn main() -> io::Result<()> {
|
||||
} else {
|
||||
PathBuf::from(".")
|
||||
};
|
||||
|
||||
process_compressed_files(&start_path)?;
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user