[ACCEPTED]-What are reserved filenames for various platforms?-naming

Accepted answer
Score: 18

From: http://www.grouplogic.com/knowledge/index.cfm/fuseaction/view_Info/docID/111.

The following characters are invalid 15 as file or folder names on Windows using 14 NTFS: / ? < > \ : * | " and any character you can 13 type with the Ctrl key.

In addition to the 12 above illegal characters the caret ^ is also 11 not permitted under Windows Operating Systems 10 using the FAT file system.

Under Windows 9 using the FAT file system file and folder 8 names may be up to 255 characters long.

Under 7 Windows using the NTFS file system file 6 and folder names may be up to 256 characters 5 long.

Under Window the length of a full path 4 under both systems is 260 characters.

In 3 addition to these characters, the following 2 conventions are also illegal:

  • Placing a space at the end of the name
  • Placing a period at the end of the name

The following 1 file names are also reserved under Windows:

  • aux,
  • com1,
  • com2,
  • ...
  • com9,
  • lpt1,
  • lpt2,
  • ...
  • lpt9,
  • con,
  • nul,
  • prn
Score: 8

Full description of legal and illegal filenames 1 on Windows: http://msdn.microsoft.com/en-us/library/aa365247.aspx

Score: 7

A tricky Unix gotcha when you don't know:

Files 5 which start with - or -- are legal but a 4 pain in the butt to work with, as many command 3 line tools think you are providing options 2 to them.

Many of those tools have a special 1 marker "--" to signal the end of the options:

gzip -9vf -- -mydashedfilename
Score: 7

As others have said, device names like COM1 15 are not possible as filenames under Windows 14 because they are reserved devices.

However, there 13 is an escape method to create and access 12 files with these reserved names, for example, this 11 command will redirect the output of the 10 ver command into a file called COM1:

ver > "\\?\C:\Users\username\COM1"

Now you 9 will have a file called COM1 that 99% of 8 programs won't be able to open, and will 7 probably freeze if you try to access.

Here's the Microsoft article that 6 explains how this "file namespace" works. Basically 5 it tells Windows not to do any string processing 4 on the text and to pass it straight through 3 to the filesystem. This trick can also 2 be used to work with paths longer than 260 1 characters.

Score: 4

The boost::filesystem Portability Guide has a lot of good 1 info.

Score: 2

Well, for MSDOS/Windows, NUL, PRN, LPT<n> and 2 CON. They even cause problems if used with 1 an extension: "NUL.TXT"

Score: 1

Unless you're touching special directories, the 8 only illegal names on Linux are '.' and '..'. Any 7 other name is possible, although accessing 6 some of them from the shell requires using 5 escape sequences.

EDIT: As Vinko Vrsalovic 4 said, files starting with '-' and '--' are 3 a pain from the shell, since those character 2 sequences are interpreted by the application, not 1 the shell.

More Related questions