judge is_dir first.

This commit is contained in:
licsber 2024-09-08 10:27:01 +08:00
parent 3edc4369f4
commit a99523f4e6

View File

@ -5,7 +5,10 @@ use std::process::Command;
use std::env; 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() {
return Err(io::Error::new(io::ErrorKind::Other, "Not a directory"));
}
println!("Processing directory: {}", path.display()); println!("Processing directory: {}", path.display());
for entry in fs::read_dir(path)? { for entry in fs::read_dir(path)? {
let entry_path = entry?.path(); let entry_path = entry?.path();
@ -35,7 +38,6 @@ fn process_compressed_files(path: &Path) -> io::Result<()> {
} }
} }
} }
}
Ok(()) Ok(())
} }