[][src]Function async_std::fs::read_dir

pub async fn read_dir<P: AsRef<Path>>(path: P) -> Result<ReadDir>

Returns a stream over the entries within a directory.

The stream yields items of type io::Result<DirEntry>. New errors may be encountered after a stream is initially constructed.

This function is an async version of std::fs::read_dir.

Errors

An error will be returned in the following situations (not an exhaustive list):

  • path does not exist.
  • path does not point at a directory.
  • The current process lacks permissions to view the contents of path.

Examples

use async_std::fs;
use async_std::prelude::*;

let mut dir = fs::read_dir(".").await?;

while let Some(entry) = dir.next().await {
    let entry = entry?;
    println!("{:?}", entry.file_name());
}