Skip to content

Instantly share code, notes, and snippets.

@arifai
Created December 30, 2019 14:53
Show Gist options
  • Save arifai/efe26fa29b43670f0bcd222566d4023f to your computer and use it in GitHub Desktop.
Save arifai/efe26fa29b43670f0bcd222566d4023f to your computer and use it in GitHub Desktop.
Listing file & folder with Rust
[package]
name = "sysinfo"
version = "0.1.0"
authors = ["Ahmad Rifa'i <arifai209@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
# sys-info = "*"
whoami = "0.6.0"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
reqwest = "0.9.24"
dirs = "2.0.2"
use std::fs;
use std::path::PathBuf;
extern crate dirs;
fn main() {
let home = dirs::home_dir().unwrap();
let home2 = home.into_os_string().into_string().unwrap();
let from_path: PathBuf = ["{}", &home2, "Documents"].iter().collect();
let _display = from_path.display();
println!("From path: {}", _display);
let paths = fs::read_dir(&from_path).unwrap();
for path in paths {
println!("List: {}", path.unwrap().path().display())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment