globwalk
A Rust crate for recursively finding files in a directory using gitignore-style glob patterns.
Repository Health
Technical Analysis
globwalk combines directory traversal with glob matching in a single crate for Rust. It walks a directory tree with walkdir and matches each entry against one or more patterns using the ignore crate’s gitignore-style syntax, so callers get extended glob features — brace expansion ({a,b}), negation (!pattern), and multiple simultaneous patterns — that the standard glob crate does not offer.
The crate exposes both a quick one-line glob() function for simple cases and a GlobWalkerBuilder for fine-grained control: minimum/maximum traversal depth, symlink following, open file-descriptor limits, custom sort order, contents-first iteration, case-insensitive matching, and file-type filtering (file/dir/symlink via a bitflags-based FileType). The resulting GlobWalker implements Iterator, yielding walkdir::DirEntry values wrapped in a Result so callers can handle traversal errors alongside matches.
The README is candid that the crate is now in maintenance mode and that the glob crate (which absorbed most of globwalk’s original advantages over time) is a reasonable default for new projects — making globwalk most useful today for existing consumers or projects that specifically need its negation and multi-pattern matching.
What You Get
- One-line globbing - the
glob()function recursively matches a single pattern against the current directory with no builder boilerplate. - GlobWalkerBuilder - a chainable builder for multi-pattern searches with control over base directory, depth, symlinks, sort order, and file-type filtering.
- Gitignore-style pattern syntax - brace expansion (
{png,jpg,gif}) and negation (!pattern) for excluding matches, both absent from the standardglobcrate. - File-type filtering - a
bitflags-basedFileType(FILE, DIR, SYMLINK) that can be OR’d to restrict which entry kinds are yielded. - Standard iterator output - yields
Result<walkdir::DirEntry, walkdir::Error>, so traversal errors surface alongside matches instead of being silently dropped.
Common Use Cases
- Build scripts and CLIs - collecting all files matching an extension set (e.g.
*.{png,jpg,gif}) across a project tree for processing or packaging. - Excluding generated or vendored paths - using negative patterns like
!targetor!Pictures/*to skip directories without a second filtering pass. - Bounded directory scans - limiting traversal with
max_depth/min_depthwhen only a shallow slice of a tree needs to be searched. - File-type-scoped searches - filtering to only directories or only files while walking, useful for tools that need to distinguish the two (e.g. cleanup or linting scripts).
Under The Hood
Architecture
The entire crate lives in a single src/lib.rs organized around a builder-to-iterator handoff: GlobWalkerBuilder accumulates configuration (root path, patterns, walkdir::WalkDir options, case sensitivity, file-type filter) and build() compiles the patterns into an ignore::overrides::Override matcher, producing a GlobWalker that implements Iterator by pulling from walkdir::IntoIter and testing each entry against the compiled override, skipping whole subtrees when a directory itself is excluded. There is no internal module layering since the crate’s entire surface area is the builder/iterator pair plus a GlobError wrapper around ignore::Error.
Tech Stack
Pure Rust (edition 2021), built on three focused dependencies: walkdir for directory traversal, ignore (from the ripgrep project) for gitignore-syntax pattern compilation and matching, and bitflags for the FileType filter flags. Dev-dependencies (tempfile, docmatic) support the test suite and doctest verification; there is no async runtime, no unsafe code, and no platform-specific logic beyond a Windows path-separator normalization in the absolute-path entry point.
Code Quality
The crate has a substantial embedded unit-test module covering absolute-path globbing, multi-pattern matching, case-insensitive matching, blacklist/negation patterns, directory-level exclusion, single-star matching, and file-type filtering, plus a separate tests/docs.rs that runs docmatic against the README’s code samples to keep documentation examples honest. CI (GitHub Actions) runs the test suite across stable/beta/nightly toolchains, re-runs library tests against a pinned MSRV (1.70.0) on Linux and Windows, and enforces cargo fmt plus warnings-as-errors on a dedicated lint job. The crate also carries #![warn(missing_docs)], keeping the public API documented by convention rather than convention alone. Error handling is explicit throughout: a GlobError type wraps pattern-compilation failures and traversal errors surface as Result items in the iterator rather than being swallowed.
API Design
The public surface is small and consistent: a one-line glob() for the common case and a fluent GlobWalkerBuilder for everything else, with method names that mirror walkdir’s own vocabulary (min_depth, max_depth, follow_links, sort_by) so users already familiar with walkdir face little relearning. The standout ergonomic win over the standard glob crate is negation and multi-pattern support, letting callers express “match these, but exclude those” in a single pattern list instead of post-filtering results. The one notable friction point for adoption is that the README itself now recommends the glob crate for new projects, since glob has closed much of the original feature gap — an unusually transparent signal that shapes how a newcomer should weigh choosing this crate today.