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.

Get All Files With A Certain Extension Recursively In Rust

rust
//! ```cargo
//! [package]
//! edition = "2021"
//! [dependencies]
//! walkdir = "2"
//! ```


use std::path::PathBuf;
use walkdir::WalkDir;


fn get_files_in_dir_matching_extension_recursively(dir: &str, exts: Vec<&str>) -> Vec<PathBuf> {
    WalkDir::new(dir)
        .into_iter()
        .filter(|e| 
            match e.as_ref().unwrap().path().extension() {
                Some(x) => exts.contains(&x.to_str().unwrap()),
                None => false
    }).map(|e| e.unwrap().into_path()).collect()
}


fn main() {
    let files = list_files(
        "recursive_test/example",vec!["txt"]
    );
    dbg!(files);
}
results start