Last active
April 2, 2022 01:19
-
-
Save snicmakino/afcbeb8b29e97efcca7aa04dfaecce67 to your computer and use it in GitHub Desktop.
Rustでlsを書いた(ファイル一覧表示のみ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs; | |
fn main() { | |
let target = "./"; | |
let mut files: Vec<String> = Vec::new(); | |
for path in fs::read_dir(target).unwrap() { | |
files.push(path.unwrap().path().display().to_string().replacen(target, "", 1)) | |
} | |
files.sort(); | |
let strings = files.iter() | |
.fold(String::new(), |joined, s| { | |
if joined == String::new() { s.to_string() } else { joined + " " + s } | |
}); | |
println!("{}", strings) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment