pub struct WalkBuilder { /* private fields */ }fs only.Expand description
Builder for a directory Walk, providing a simpler API over the
ignore crate for the most common cases.
Created with cu::fs::walker.
Implementations§
Source§impl WalkBuilder
impl WalkBuilder
Sourcepub fn as_inner_mut(&mut self) -> &mut IgnoreWalkBuilder
pub fn as_inner_mut(&mut self) -> &mut IgnoreWalkBuilder
Return the inner WalkBuilder from the ignore crate for advanced configuration.
Note that the overrides matcher will be replaced when building the walker
Sourcepub fn glob_includes(
&mut self,
globs: impl IntoIterator<Item = impl AsRef<str>>,
) -> Result<&mut Self>
pub fn glob_includes( &mut self, globs: impl IntoIterator<Item = impl AsRef<str>>, ) -> Result<&mut Self>
Add glob patterns to include. By default all paths are included.
Patterns use gitignore-style glob syntax (as implemented by the ignore
crate), which supports *, **, ?, [...] character classes, and
{a,b} brace alternation. Once any include pattern is added, only paths
matching at least one include (and no exclude) are yielded.
§Caution
If the glob pattern starts with ./, the dot is removed instead of matching
literal ./. Patterns starting with ../ still
matches the literal ../ (meaning the root must start with ../ to produce any match)
let mut walker = cu::fs::walker(".");
// include Rust and TOML files anywhere in the tree
walker.glob_includes(["**/*.{rs,toml}"])?;
for entry in walker.walk()? {
cu::info!("{}", entry?.path().display());
}Sourcepub fn glob_excludes(
&mut self,
globs: impl IntoIterator<Item = impl AsRef<str>>,
) -> Result<&mut Self>
pub fn glob_excludes( &mut self, globs: impl IntoIterator<Item = impl AsRef<str>>, ) -> Result<&mut Self>
Add glob patterns to exclude. By default nothing is excluded.
§Caution
If the glob pattern starts with ./, the dot is removed instead of matching
literal ./. Patterns starting with ../ still
matches the literal ../ (meaning the root must start with ../ to produce any match)
let mut builder = cu::fs::walker(".");
builder.glob_excludes(["**/*.{log,tmp}"])?;
for entry in builder.walk()? {
cu::info!("{}", entry?.path().display());
}Sourcepub fn include_dir_entries(&mut self, include: bool) -> &mut Self
pub fn include_dir_entries(&mut self, include: bool) -> &mut Self
Set whether directory entries are returned while iterating. Default is
false (only files are yielded).
When enabled, directory entries and symlinks-to-directories are also
yielded (as well as the root of the walk, at depth 0). Note that the
files inside a symlinked directory are still not returned unless
follow_links is also enabled.
Sourcepub fn git(&mut self, yes: bool) -> &mut Self
pub fn git(&mut self, yes: bool) -> &mut Self
Enable reading .gitignore and git exclude configs, (mostly) matching
git’s own behavior. Default is disabled.
Because this relies on git configuration, ignore rules are only applied when the walk root is inside a git repository.
Skip hidden files. Default is false (i.e. hidden files are
included).
Sourcepub fn follow_links(&mut self, yes: bool) -> &mut Self
pub fn follow_links(&mut self, yes: bool) -> &mut Self
Follow symbolic links. Default is false.