#![forbid(unsafe_code)]
#![forbid(missing_docs)]
use std::path::Path;
use std::path::PathBuf;
pub fn walkdown(
start: impl AsRef<Path>,
task: &mut impl FnMut(PathBuf) -> std::io::Result<()>,
) -> std::io::Result<()> {
let start_dir = start.as_ref().to_path_buf();
if !start_dir.is_dir() {
return Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!(
"The directory '{}' does not exist or is not a directory.",
start_dir.display()
),
));
}
let original_dir = std::env::current_dir()?;
std::env::set_current_dir(&start_dir)?;
let base_dir = std::env::current_dir()?;
task(base_dir.clone())?;
for entry in std::fs::read_dir(".")? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
walkdown(&path, task)?; }
}
std::env::set_current_dir(&original_dir)?;
Ok(())
}