fn judge file is compressed.

This commit is contained in:
licsber 2024-09-08 11:16:32 +08:00
parent bd58da1c17
commit 42411d7324

View File

@ -22,13 +22,23 @@ fn unar_file(path: &Path) -> io::Result<()> {
}
Err(e) => {
eprintln!("Failed to execute unar for {:?}: {}", path, e);
return Err(e);
}
}
Ok(())
}
fn is_compressed(path: &Path) -> bool {
if let Some(ext) = path.extension() {
if let Some(ext) = ext.to_str() {
let ext = ext.to_lowercase();
return ext == "zip" || ext == "rar";
}
}
false
}
fn process_compressed_files(path: &Path) -> io::Result<()> {
if !path.is_dir() {
return Err(io::Error::new(io::ErrorKind::Other, "Not a directory"));
@ -39,10 +49,8 @@ fn process_compressed_files(path: &Path) -> io::Result<()> {
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" {
unar_file(&entry_path).expect("UNAR Error.");
}
} else if is_compressed(entry_path.as_path()) {
unar_file(&entry_path).expect("UNAR Error.");
}
}