Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

semi colons in Windows filenames?

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.

like image 516
Jeff Avatar asked Oct 06 '10 04:10

Jeff


People also ask

Are colons allowed in Windows filenames?

There are a few characters that simply aren't allowed in Windows filenames, the colon is one of them. Sorry. P.S. the full list of invalid characters is here: msdn.microsoft.com/en-us/library/windows/desktop/… It might be possible to do this with the native API or from a device driver.

What can I use instead of colon in filename?

Unfortunately, the Mac's HFS+ file system uses the COLON as a path separator just as Unix-like OSes use SOLIDUS / (slash) and Microsoft OSes use REVERSE SOLIDUS \ (backslash).


2 Answers

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).

like image 186
Michael Petrotta Avatar answered Sep 20 '22 18:09

Michael Petrotta


Though it may be omitted in the Windows handbooks, the semicolon is a reserved character too, for example "dir .dat;.bak" is a legal command. The same applies to the plus character, for example "copy test1.dat+test2.dat test3.dat" is a legal command.

like image 20
Vertilizer Avatar answered Sep 16 '22 18:09

Vertilizer