views:

47

answers:

3

Hi All, One of my users asked why my app does not support semi-colons in filenames. I stepped through my code, seems Windows function GetOpenFileName truncates any filename containing a semi-colon. e.g. "one;two.wav" -> "one".

Microsoft says colons are not allowed, but don't mention semi-colons...

http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx

Are they legal or not?

EDIT: ..and how to GetOpenFileName() to work with semi-colons in filename?

OH!, Weird - 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.

A: 

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 Win7 system. Watch for code, probably yours or third-party code, that does strange things with unexpected characters (most notably spaces).

Michael Petrotta
Actually, colons (`:`) are reserved for NTFS alternate data streams. You can therefore do this in a command window: `echo NUL > foo` then `echo hello > foo:bar`.
Benoit
A: 

Yes, they are allowed. Just that if you are running them in the command line you have to put quotes within them.

cherhan
A: 

Yes. A semi-colon is a legal character in a Windows file-name. It wouldn't surprise me, though, if there were other programs that had a problem with them.

Andrew Cooper