fn judge file is compressed.
This commit is contained in:
parent
bd58da1c17
commit
42411d7324
16
src/main.rs
16
src/main.rs
@ -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,12 +49,10 @@ 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" {
|
||||
} else if is_compressed(entry_path.as_path()) {
|
||||
unar_file(&entry_path).expect("UNAR Error.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user