init commit.

This commit is contained in:
2024-09-07 23:53:17 +08:00
commit 7731c177c9
8 changed files with 86 additions and 0 deletions

39
src/main.rs Normal file
View 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(())
}