# Function bitflags::__core::fs::read_dir [−] [src]

    pub fn read_dir<P>(path: P) -> Result<ReadDir, Error> where P: AsRef<Path>

1.0.0

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.

# Platform-specific behavior

This function currently corresponds to the `opendir` function on Unix and the `FindFirstFile` function on Windows. Note that, this may change in the future.

# Errors

This function will return an error in the following situations, but is not limited to just these cases:

- The provided `path` doesn't exist.
- The process lacks permissions to view the contents.
- The `path` points at a non-directory file.

# Examples

    use std::io;
    use std::fs::{self, DirEntry};
    use std::path::Path;

    // one possible implementation of walking a directory only visiting files
    fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> {
        if try!(fs::metadata(dir)).is_dir() {
            for entry in try!(fs::read_dir(dir)) {
                let entry = try!(entry);
                if try!(fs::metadata(entry.path())).is_dir() {
                    try!(visit_dirs(&entry.path(), cb));
                } else {
                    cb(&entry);
                }
            }
        }
        Ok(())
    }

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)