Hillboy
Hillboy

Reputation: 685

CreateFile(...) with abnormal path such as "C:\\test\\\\file.txt" implications

Are there any unforeseen consequences when create a file with two backslashes in it's path.

In this code the file creates fine but I'm wondering if there are any side-effects I may see down the road with this file.

 HANDLE hFile = CreateFile(
    TEXT("C:\\test\\\\file.txt"),                
    GENERIC_WRITE,          
    0,                      
    NULL,                   
    CREATE_NEW,             
    FILE_ATTRIBUTE_NORMAL,  
    NULL
);             

Upvotes: 2

Views: 394

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385088

No. Windows will generate a canonical path from the string you give it. That includes resolving relative paths (including the collapse of . and the expansion of ..) and collapsing redundant path separators.

The file will be called file.txt and will live under \test on the C: drive, and that's that.

This is actually not documented, as far as I can tell, which is kind of weird.

Upvotes: 3

Related Questions