Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Find A File In A Directory Tree By Name In Rust

TODO : Fill this out

rust
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])
}