Struct scan_dir::ScanDir
[−]
[src]
pub struct ScanDir { /* fields omitted */ }
Settings for directory walker
Methods
impl ScanDir
[src]
fn all() -> ScanDir
Constructs a settings that iterates over all entries
Just a starting point if you need complete control
fn files() -> ScanDir
Constructs a settings which only iterates over files (non-directories).
The hidden and backup files are ignored by default
fn dirs() -> ScanDir
Constructs a settings which only iterates over directories
The directories which match hidden and backup patterns are excluded
Skip hidden files
Hidden files are the ones having the name starting with dot .
(on all platforms)
fn skip_dirs(&mut self, flag: bool) -> &mut ScanDir
Skip directory entries
fn skip_files(&mut self, flag: bool) -> &mut ScanDir
Skip file (non-directory) entries
fn skip_symlinks(&mut self, flag: bool) -> &mut ScanDir
Skip symlinks
By default symlinks are resolve if either skip_dirs or skip_files are enabled. So symlink is treated just like entry it points to. This method allows to avoid stat call and skip symlinks at all.
If neither skip_files
nor skip_dirs
is enabled the symlink is
never resolved and is returned just like any other directory entry.
fn skip_backup(&mut self, flag: bool) -> &mut ScanDir
Skip backup files
This is expected to skip entries that different editors and version control systems keep as backup files. We currently do not have precise control over this thing, so you may consider turn this off and filter entries yourself, if precise control is required.
You may also just filter files by extension instead of using this.
This is mostly useful if hidden files are also skipped.
Currently we ignore the following patterns:
*.bak
*~
-- vim/emacs/other backup files#*#
-- emacs auto save
fn read<P: AsRef<Path>, R: Sized, F>(&self, path: P, f: F) -> Result<R, Error> where
F: FnOnce(Iter) -> R,
F: FnOnce(Iter) -> R,
Calls a closure with an iterator over pairs of (entry, name)
Note when it comes to error reporting, here is how errors are prioritized:
- If there is scan_dir error it has priority over result/error of the closure
- The
Io
error have more priority overDecode
error - Otherwise first received error is returned if there are multiple
Example
use scan_dir::ScanDir; ScanDir::files().read(".", |iter| { for (entry, name) in iter { println!("File {:?} has full path {:?}", name, entry.path()); } }).unwrap()
fn walk<P: AsRef<Path>, R: Sized, F>(
&self,
path: P,
f: F
) -> Result<R, Vec<Error>> where
F: FnOnce(Walker) -> R,
&self,
path: P,
f: F
) -> Result<R, Vec<Error>> where
F: FnOnce(Walker) -> R,
Calls a closure with recursive walker over the directory
The recursive walker continues to work even if error occured and returns a list of the errors in the case at least one error takes place. You may put some mutable variable on the stack and put the result of the closure there, in case you need to tolerate errors.
Example
This is an example walker which tolerates errors
use scan_dir::ScanDir; let mut all_files = Vec::new(); let walk_result = ScanDir::files().walk(".", |iter| { for (entry, name) in iter { all_files.push(entry.path()); } }); if let Err(errors) = walk_result { for e in errors { println!("Error {}. Continue scanning...", e); } }
Trait Implementations
impl Debug for ScanDir
[src]
impl Clone for ScanDir
[src]
fn clone(&self) -> ScanDir
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more