Function smol::fs::read_dir

source · []
pub async fn read_dir<P>(path: P) -> Result<ReadDir, Error> where
    P: AsRef<Path>, 
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());
}