#directory #walk #glob #read-dir #filename

scan_dir

A easier read_dir and recursive directory walker, useful for reading directory of config files

5 unstable releases

Uses old Rust 2015

0.3.3 Apr 20, 2016
0.3.2 Dec 25, 2015
0.3.1 Oct 27, 2015
0.2.0 Sep 25, 2015
0.1.0 Sep 24, 2015

#1566 in Filesystem

Download history 164/week @ 2024-01-09 118/week @ 2024-01-16 122/week @ 2024-01-23 123/week @ 2024-01-30 149/week @ 2024-02-06 190/week @ 2024-02-13 380/week @ 2024-02-20 179/week @ 2024-02-27 180/week @ 2024-03-05 162/week @ 2024-03-12 121/week @ 2024-03-19 96/week @ 2024-03-26 181/week @ 2024-04-02 190/week @ 2024-04-09 254/week @ 2024-04-16 157/week @ 2024-04-23

795 downloads per month
Used in 6 crates

MIT/Apache

42KB
616 lines

Scan Dir

Status:Beta
Documentation:http://tailhook.github.com/scan_dir/

Simple interface to iterate over files or subdirs of a directory

Features:

  1. Ensure that file names are decodable to utf-8 (or error/warning is propagated)
  2. Ignore hidden entries (by default)
  3. Ignore common text editor and revision control backup files
  4. Select only files or only directories
  5. Simpler but detailed enough error handling
  6. Recursive directory scanner

Here is the example:

use scan_dir::ScanDir;

ScanDir::dirs().read(".", |iter| {
    for (entry, name) in iter {
        println!("File {:?} has full path {:?}", name, entry.path());
    }
}).unwrap()

Compare it to stdlib way:

use std::fs::read_dir;
for entry_res in read_dir(".").unwrap() {
    let entry = entry_res.unwrap();
    let file_name_buf = entry.file_name();
    let file_name = file_name_buf.to_str().unwrap();
    if !file_name.starts_with(".") &&
        entry.file_type().unwrap().is_dir()
    {
        println!("File {:?} has full path {:?}",
            file_name, entry.path());
    }
}

Well, it looks almost fine until you want to turn unwrap's into correct error reporting.

Upgrading

The scan_dir 0.3 by default resolves symlink before checking if it's a file or directory. In the scan_dir 0.1-0.2 symlinks where always included in the list (i.e. they were skipped neither by skip_files nor by skip_dirs).

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~47KB