I try run this program:
use std::io::stdin;
use std::collections::HashSet;
use std::ffi::OsString;
use std::fs::File;
fn main(){
let mut end_of_input:bool=false;
let mystdin=stdin();
let mut input_filename=String::new();
let mut attr_map=HashSet::new();
while !end_of_input{
let result=mystdin.read_line(&mut input_filename);
end_of_input=result.is_err();
if !end_of_input{
proccess_file(input_filename.clone(),&mut attr_map);
}
}
}
fn proccess_file(input:String,attr_map:&mut HashSet<String>){
println!("{}",input);
let mut os_string=OsString::from(input);
println!("{}",os_string.to_str().unwrap());
let file=File::open(os_string.as_os_str()).expect("File not found");
}
When running, I input some absolute file path (for example: C:/a.txt
), and programs panics: "
Syntax error in file name, folder name, or volume label.". So, windows cannot open file with valid filename. May be I do something wrong?