Function read_dir
fn read_dir<P: AsRef<crate::path::Path>>(path: P) -> io::Result<ReadDir>
Returns an iterator over the entries within a directory.
The iterator will yield instances of [io::Result]<[DirEntry]>.
New errors may be encountered after an iterator is initially constructed.
Entries for the current and parent directories (typically . and ..) are
skipped.
The order in which read_dir returns entries can change between calls. If reproducible
ordering is required, the entries should be explicitly sorted.
Platform-specific behavior
This function currently corresponds to the opendir function on Unix
and the FindFirstFileEx function on Windows. Advancing the iterator
currently corresponds to readdir on Unix and FindNextFile on Windows.
Note that, this may change in the future.
The order in which this iterator returns entries is platform and filesystem dependent.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
- The provided
pathdoesn't exist. - The process lacks permissions to view the contents.
- The
pathpoints at a non-directory file.
Examples
use io;
use ;
use Path;
// one possible implementation of walking a directory only visiting files
use ;