async-std/examples/list-dir.rs

24 lines
512 B
Rust
Raw Normal View History

2019-08-08 12:44:48 +00:00
//! Lists files in a directory given as an argument.
use std::env::args;
2019-08-14 01:47:39 +00:00
use async_std::fs;
use async_std::io;
use async_std::prelude::*;
use async_std::task;
2019-08-08 12:44:48 +00:00
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(res) = dir.next().await {
let entry = res?;
println!("{}", entry.file_name().to_string_lossy());
2019-08-08 12:44:48 +00:00
}
Ok(())
})
}