- Status
Beta
- Documentation
Simple interface to iterate over files or subdirs of a directory
Features:
- Ensure that file names are decodable to utf-8 (or error/warning is propagated)
- Ignore hidden entries (by default)
- Ignore common text editor and revision control backup files
- Select only files or only directories
- Simpler but detailed enough error handling
- 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.
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
).
Licensed under either of
- Apache License, Version 2.0, (./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.