Skip to content

Instantly share code, notes, and snippets.

@snicmakino
Last active April 2, 2022 01:19
Show Gist options
  • Save snicmakino/afcbeb8b29e97efcca7aa04dfaecce67 to your computer and use it in GitHub Desktop.
Save snicmakino/afcbeb8b29e97efcca7aa04dfaecce67 to your computer and use it in GitHub Desktop.
Rustでlsを書いた(ファイル一覧表示のみ)
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