windowsgetopenfilename

Semicolons in Windows filenames


One of my users asked why my application does not support semicolons in filenames. I stepped through my code, and it seems Windows function GetOpenFileName truncates any filename containing a semicolon. E.g., "one;two.wav" -> "one".

Microsoft says colons are not allowed, but it doesn't mention semicolons...

Naming Files, Paths, and Namespaces

Are they legal or not?

And how can I get GetOpenFileName() to work with semicolons in a filename?

OH! Weird; the filename is correct, except 'scrolled' off to the left. So "one;two.wav" looks like "two.wav" until I click it and press left-arrow (then it's fine). So it's not a bug as such, only weird behaviour.


Solution

  • Semicolons are legal in NTFS file paths.

    Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:

    The following reserved characters:

    • < (less than)
    • > (greater than)
    • : (colon)
    • " (double quote)
    • / (forward slash)
    • \ (backslash)
    • | (vertical bar or pipe)
    • ? (question mark)
    • * (asterisk)
    • Integer value zero, sometimes referred to as the ASCII NUL character.
    • Characters whose integer representations are in the range from 1 through 31, except for alternate streams where these characters are allowed.
    • Any other character that the target file system does not allow.

    I'm able to add semicolons to filenames on my Windows 7 system. Watch for code, probably yours or third-party code, that does strange things with unexpected characters (most notably spaces).