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.

Read Files In A Directory Recursively In Rust

TODO: Pull subtitle into page object
Code
//! ```cargo
//! [package]
//! edition = "2021"
//! [dependencies]
//! walkdir = "2"
//! ```

use walkdir::{DirEntry, WalkDir};

fn is_hidden(entry: &DirEntry) -> bool {
    entry.file_name()
         .to_str()
         .map(|s| s.starts_with("."))
         .unwrap_or(false)
}

fn main() {
  let walker = WalkDir::new("recursive_test").into_iter();
  for entry in walker.filter_entry(|e| !is_hidden(e)) {
      let entry = entry.unwrap();
      println!("{}", entry.path().display());
  }
}
Results
recursive_test
recursive_test/example
recursive_test/example/a
recursive_test/example/a/2.txt
recursive_test/example/a/c
recursive_test/example/a/c/4.txt
recursive_test/example/a/c/delta.html
recursive_test/example/alfa.html
recursive_test/example/1.txt
recursive_test/example/bravo.html
recursive_test/example/b
recursive_test/example/b/3.txt
recursive_test/example/b/charlie.html

Notes

Debugging Stuff

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

        -- title

Read Files In A Directory Recursively In Rust

-- code
-- rust

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

use walkdir::{DirEntry, WalkDir};

fn is_hidden(entry: &DirEntry) -> bool {
    entry.file_name()
         .to_str()
         .map(|s| s.starts_with("."))
         .unwrap_or(false)
}

fn main() {
  let walker = WalkDir::new("recursive_test").into_iter();
  for entry in walker.filter_entry(|e| !is_hidden(e)) {
      let entry = entry.unwrap();
      println!("{}", entry.path().display());
  }
}

-- results/

recursive_test
recursive_test/example
recursive_test/example/a
recursive_test/example/a/2.txt
recursive_test/example/a/c
recursive_test/example/a/c/4.txt
recursive_test/example/a/c/delta.html
recursive_test/example/alfa.html
recursive_test/example/1.txt
recursive_test/example/bravo.html
recursive_test/example/b
recursive_test/example/b/3.txt
recursive_test/example/b/charlie.html

-- /results


-- notes

- This version skips hidden files and directories

- It will error if it tries to access a file or
directory it doesn't have permission to open

-- categories
-- Rust 

-- metadata
-- date: 2023-12-16 16:33:51
-- id: 2zdqiego
-- site: aws
-- type: post
-- status: published