init commit.
This commit is contained in:
39
src/main.rs
Normal file
39
src/main.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
fn process_compressed_files(path: &Path) -> io::Result<()> {
|
||||
if path.is_dir() {
|
||||
for entry in fs::read_dir(path)? {
|
||||
let entry_path = 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")) {
|
||||
let output = Command::new("unar")
|
||||
.arg(path)
|
||||
.output();
|
||||
|
||||
match output {
|
||||
Ok(result) => {
|
||||
if !result.status.success() {
|
||||
eprintln!("Error processing compressed file {:?}: {}", path, String::from_utf8_lossy(&result.stderr));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to execute unar for {:?}: {}", path, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let start_path = PathBuf::from(".");
|
||||
process_compressed_files(&start_path)?;
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user