I'm trying to learn Rust, but even with a very simple program i'm hitting a wall.
The app goal is to read a path from cmd line and list the directory content of that path.
If I hardcode any path, it works without any error. If i use the path entered by the user, the error thread 'main' panicked at 'Reading directory failed: Os { code: 123, kind: InvalidFilename, message: "The filename, directory name, or volume label syntax is incorrect." }', src\main.rs:20:37
.
My code:
use std::fs::read_dir;
use std::io;
use std::ffi::OsString;
fn main() {
println!("Please input the path of the directory.");
let mut buffer = String::new();
io::stdin()
.read_line(&mut buffer)
.expect("Failed to read line");
let mut osString : OsString = OsString::new();
osString.push(&buffer[0..buffer.len()]);
let paths = read_dir(&osString).expect("Reading directory failed");
Thanks in advance for your help.