walk
only.Expand description
Traversal and matching of files and directory trees.
This module provides APIs for walking directory trees and matching files in a directory tree
against Program
s using Iterator
s. These iterators implement FileIterator
, which
supports efficient filtering that can cancel traversal into sub-trees that are discarded by
combinators.
Examples
To iterate over the files in a directory tree, use the PathExt
trait.
use std::path::Path;
use wax::walk::{Entry, PathExt as _};
let root = Path::new(".config");
for entry in root.walk() {
let entry = entry.unwrap();
println!("{:?}", entry.path());
}
To match a Glob
against a directory tree, use Glob::walk
. This function constructs an
iterator that efficiently matches a Glob
against the paths of files read from a directory
tree.
use wax::walk::Entry;
use wax::Glob;
let glob = Glob::new("**/src/**").unwrap();
for entry in glob.walk("projects") {
let entry = entry.unwrap();
println!("{:?}", entry.path());
}
Any FileIterator
(the iterators constructed by Glob::walk
, PathExt::walk
, etc.) can
be efficiently filtered. This filtering can cancel traversal into sub-trees that are discarded.
To filter files using Program
s, use the not
combinator.
use std::path::Path;
use wax::walk::{Entry, FileIterator, PathExt as _};
let root = Path::new(".config");
for entry in root.walk().not(["**/*.xml"]).unwrap() {
let entry = entry.unwrap();
println!("{:?}", entry.path());
}
More arbitrary (non-nominal) filtering is also possible via the filter_entry
combinator.
Structs
- Iterator combinator that filters file entries and controls the traversal of directory trees.
- Describes a file with a path matching a
Glob
in a directory tree. - Describes iteration over matching files in a directory tree.
- Iterator combinator that filters file entries with paths that match patterns.
- Describes a file yielded from a
WalkTree
iterator. - Configuration for walking directory trees.
- Describes errors that occur when walking a directory tree.
- A
FileIterator
over files in a directory tree.
Enums
- Describes how file entries are read and discarded by
FileIterator::filter_entry
. - Configuration for interpreting symbolic links.
Traits
- Describes a file yielded from a
FileIterator
. - An
Iterator
over files in a directory tree. - Functions for walking a directory tree at a
Path
.