How to create a file with colons in the name? (example: hours)

I am trying to create a file with colons in the name, but this code fails

Windows 10
rustc 1.37.0

use std::fs::File;

fn main() {
    println!("Hello, world!");
    let f = File::create("01-01-2019 16:50:30.txt".to_string()).expect("Unable to create file");
    // let f = File::create("./01-01-2019 16:50:30.txt".to_string()).expect("Unable to create file");
}

Absolute and relative paths fail too

If I remove the colons, the code works.

How can I create the file?

Thanks

Colon is one of the reserved characters in Windows paths.

2 Likes

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