The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Get A List Of Files Recursively While Excluding Extensions And Hidden Files In Rust

TODO: Pull subtitle into page object
Code
//! ```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
[_active_nvim_run:15] files = [
    "recursive_test/example/a/c/delta.html",
    "recursive_test/example/alfa.html",
    "recursive_test/example/bravo.html",
    "recursive_test/example/b/charlie.html",
]

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Get A List Of Files Recursively While Excluding Extensions And Hidden Files In Rust

-- code
-- 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/

[_active_nvim_run:15] files = [
    "recursive_test/example/a/c/delta.html",
    "recursive_test/example/alfa.html",
    "recursive_test/example/bravo.html",
    "recursive_test/example/b/charlie.html",
]

-- /results


-- categories
-- Rust 

-- metadata
-- date: 2023-12-16 19:07:17
-- id: 2ze9nwam
-- site: aws
-- type: post
-- status: published