Function async_fs::read_dir

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

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.

Errors

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.

Examples

use futures_lite::stream::StreamExt;

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

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