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.
https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#file-and-directory-names

2 Likes