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

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

Returns a stream of entries in a directory.

The stream yields items of type io::Result<DirEntry>. Note that I/O errors can occur while reading from the stream.

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


An error will be returned in the following situations:

  • path does not point to an existing directory.
  • The current process lacks permissions to read the contents of the directory.
  • Some other I/O error occurred.


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

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

while let Some(res) = entries.next().await {
    let entry = res?;
    println!("{}", entry.file_name().to_string_lossy());