You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
async-std/examples/list-dir.rs

25 lines
511 B
Rust

5 years ago
//! Lists files in a directory given as an argument.
#![feature(async_await)]
use std::env::args;
5 years ago
use async_std::fs;
use async_std::io;
use async_std::prelude::*;
use async_std::task;
5 years ago
fn main() -> io::Result<()> {
let path = args().nth(1).expect("missing path argument");
task::block_on(async {
let mut dir = fs::read_dir(&path).await?;
while let Some(entry) = dir.next().await {
println!("{}", entry?.file_name().to_string_lossy());
}
Ok(())
})
}