Struct scan_dir::ScanDir [] [src]

pub struct ScanDir { /* fields omitted */ }

Settings for directory walker

Methods

impl ScanDir
[src]

Constructs a settings that iterates over all entries

Just a starting point if you need complete control

Constructs a settings which only iterates over files (non-directories).

The hidden and backup files are ignored by default

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)

Skip directory entries

Skip file (non-directory) entries

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.

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

Calls a closure with an iterator over pairs of (entry, name)

Note when it comes to error reporting, here is how errors are prioritized:

  1. If there is scan_dir error it has priority over result/error of the closure
  2. The Io error have more priority over Decode error
  3. 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()

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]

Formats the value using the given formatter.

impl Clone for ScanDir
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more