Cannot open file on windows

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?

Windows file paths use backslashes: C:\a.txt

I founded that readed string has "\r\n" at end. Windows supports forward slashes. I need method to remove this symbols.

1 Like

Now my antivirus marks my program as virus :roll_eyes:

Classic

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.