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<()> {
|
fn process_compressed_files(path: &Path) -> io::Result<()> {
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
println!("Path: {}", path.display());
|
println!("Processing directory: {}", path.display());
|
||||||
for entry in fs::read_dir(path)? {
|
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)?;
|
process_compressed_files(&entry_path)?;
|
||||||
}
|
} else if let Some(ext) = entry_path.extension().and_then(|e| e.to_str()) {
|
||||||
} else {
|
if ext == "rar" || ext == "zip" {
|
||||||
if path.extension().map_or(false, |ext|
|
println!("UNAR: {}", entry_path.display());
|
||||||
ext == "rar" || ext == "zip",
|
let parent_dir = entry_path.parent().unwrap();
|
||||||
) {
|
let filename = entry_path.file_name().to_str().unwrap();
|
||||||
println!("UNAR: {}", path.display());
|
|
||||||
let output = Command::new("unar")
|
let output = Command::new("unar")
|
||||||
.current_dir(path)
|
.current_dir(parent_dir)
|
||||||
.arg(path)
|
.arg(filename)
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
match output {
|
match output {
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
if !result.status.success() {
|
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) => {
|
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 {
|
} else {
|
||||||
PathBuf::from(".")
|
PathBuf::from(".")
|
||||||
};
|
};
|
||||||
|
|
||||||
process_compressed_files(&start_path)?;
|
process_compressed_files(&start_path)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user