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 A List Of Files Recursively While Excluding Extensions And Hidden Files In Rust

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

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

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

fn get_file_list(dir: &str, ext: Vec<&str>) -> Vec<PathBuf> {
    WalkDir::new(dir)
    .into_iter()
    .filter(|e| 
      e.as_ref().ok().and_then(|x| x.file_name().to_str())
        .map(|s| !s.starts_with(".")
      ).unwrap_or(false)
    ).filter(|e| 
        match e
          .as_ref().unwrap().path().extension() {
            Some(x) => !ext.contains(&x.to_str().unwrap()),
            None => false
    }).map(|e| e.unwrap().into_path()).collect()
}
results start