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.

Do A Glob Search For Files In A Directory With Rust

TODO: Pull subtitle into page object

Basic Recursive Glob

Code
//! ```cargo
//! [dependencies]
//! glob = "0.3.1"
//! ```


use glob::glob;

fn main() {
    for entry in glob("recursive_test/**/*.txt").expect("Failed to read glob pattern") {
        match entry {
            Ok(path) => println!("{:?}", path.display()),
            Err(e) => println!("{:?}", e),
        }
    }
}
Results
"recursive_test/example/.hidden_file_1.txt"
"recursive_test/example/.hidden_file_2.txt"
"recursive_test/example/1.txt"
"recursive_test/example/a/2.txt"
"recursive_test/example/a/c/4.txt"
"recursive_test/example/b/3.txt"

The code uses the `anyhow`` and `glob`` crates which can be installed with:

`cargo add anyhow`` `cargo add glob``

Debugging Stuff

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

        -- title

Do A Glob Search For Files In A Directory With Rust

-- h2

Basic Recursive Glob

-- code
-- rust

//! ```cargo
//! [dependencies]
//! glob = "0.3.1"
//! ```


use glob::glob;

fn main() {
    for entry in glob("recursive_test/**/*.txt").expect("Failed to read glob pattern") {
        match entry {
            Ok(path) => println!("{:?}", path.display()),
            Err(e) => println!("{:?}", e),
        }
    }
}

-- results/

"recursive_test/example/.hidden_file_1.txt"
"recursive_test/example/.hidden_file_2.txt"
"recursive_test/example/1.txt"
"recursive_test/example/a/2.txt"
"recursive_test/example/a/c/4.txt"
"recursive_test/example/b/3.txt"

-- /results






-- note

The code uses the `anyhow`` and `glob`` crates which
can be installed with:

`cargo add anyhow``
`cargo add glob``


-- ref
-- Process A Directory Recursitvely In Rust
-- post: 2pltmjun

An alternative method for processing all the files
and diretories directly instead of via the glob 
filtered set. 


-- blurb

-- categories
-- Rust 

-- metadata
-- date: 2023-05-04 17:29:44
-- id: 2plujgi8
-- site: aws
-- type: post
-- status: published