Find A File In A Directory Tree By Name In Rust
TODO: Fill this out
Code
use std::path::PathBuf;
use walkdir::WalkDir;
fn main() {
let file_path = get_path_to_file("the-target");
dbg!(&file_path);
}
fn get_path_to_file(target_name: &str) -> PathBuf {
let asdf: Vec<_> = WalkDir::new(".")
.into_iter()
.filter_map(|v| {
if let Some(name) = v.as_ref().unwrap().path().file_stem() {
if name == target_name {
Some(v.as_ref().unwrap().path().display().to_string())
} else {
None
}
} else {
None
}
})
.collect();
PathBuf::from(&asdf[0])
}