File: list-dir.rs

package info (click to toggle)
rust-async-std 1.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,992 kB
  • sloc: sh: 13; makefile: 8
file content (23 lines) | stat: -rw-r--r-- 512 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//! Lists files in a directory given as an argument.

use std::env::args;

use async_std::fs;
use async_std::io;
use async_std::prelude::*;
use async_std::task;

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());
        }

        Ok(())
    })
}