Home » Questions » Computers [ Ask a new question ]

Why can't I name a folder or file 'CON' in Windows?

Why can't I name a folder or file 'CON' in Windows?

In all versions of Windows, we are unable to rename a file or a folder name as CON without third-party file renaming software. Trying to do this in Windows 7 results in an error:

Asked by: Guest | Views: 348
Total answers/comments: 4
Guest [Entry]

"I gave this answer to a duplicate, and thought I'd post it here for your reference:

As previously stated. It's a reserved word from back in MS-DOS, for the CONsole device (as far as I can remember). But, you can force Windows/dos to create the folder for you. For devices, it uses the format \\.\[RESERVED_WORD] to access the ""file"" (these devices used files for communication). To force Windows to create your folder, instead of doing mkdir [RESERVED_WORD], do the following:

mkdir \\.\[absolute path to folder of choice, including drive letter]\[RESERVED_WORD]

For example, to create CON folder on my desktop,

mkdir \\.\C:\Users\me\Desktop\CON

To delete the folder, you have to reference it the same way, or else it won't work.

rmdir \\.\C:\Users\me\Desktop\CON

My advice though is to just use a different name. It would be very difficult to always refer to it via its absolute path, especially if you are developing an app you plan on deploying."
Guest [Entry]

"Extending Pablo Santa Cruz's answer, here is the full list of keywords
that are used by Windows internally and are reserved. 
As with all Windows filenames, the following are case insensitive.

CON
PRN
AUX
NUL
COM0, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9
LPT0, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9

Source: The specified device name is invalid at Microsoft Docs.
You can use _con instead."
Guest [Entry]

Just like there are characters that cannot be used in a filename, there are also several words (whole filenames) that cannot be used because they are reserved.
Guest [Entry]

"As mentioned, you can create and manipulate files and folders with reserved names on the command line by using a device or filename namespace such as \\.\C:\NUL, but look at what happens when you try to access such a file or folder through Windows Explorer:

Any access to an object with a reserved device name is treated as referring to the device specified by that name, unless you use the aforementioned namespace workaround. These errors occur because Windows is attempting to operate on them as if they were normal folders, but you can't open a device named NUL, CON, or otherwise as a folder—hence the Incorrect function error (which is similar to the Inappropriate ioctl for device error on Linux)."