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

30

8

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:

The specified device name is invalid.

Trying to save a file as con.txt in Notepad leads to a similar error:

This file name is reserved for use by Windows.
Choose another name and try again.

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

hari

Posted 2009-12-23T18:08:14.827

Reputation: 372

Answers

34

"con" is the name of a system I/O device, the console.

  • con
  • err
  • nul

And a couple others, I think.

In the old days it was common in DOS to create a file (and I still do this occasionally) with:

C:\>copy con foo.txt
I'm typing some text here.
^Z
    1 file(s) copied.
C:\>

JMD

Posted 2009-12-23T18:08:14.827

Reputation: 4 427

2

@Sathya: By using the \?\ prefix to bypass file name parsing. For example, " \?\C:\con\nul.txt ".

– user1686 – 2011-08-26T17:29:56.060

1A minor correction: err is not reserved. The full list of reserved device names is: con, nul, prn, com1..9, and lpt1..9. They are even reserved when used with any extension (e.g. con.txt). – efotinis – 2009-12-23T19:52:10.397

"unless we use a renaming software"

About the quoted part, how do the "renaming software" get around what is essentially an OS limitatiom – Sathyajith Bhat – 2009-12-23T19:57:03.833

1You got me. I'm sceptical that any "renaming software" can even do it. But if it can, I'd be worried about being able to open or even move the file. As you said, the OS is going to take issue with it. – JMD – 2009-12-23T20:32:54.260

11

The master list is at http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx

Do not use the following reserved device names for the name of a file:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended.

– shf301 – 2009-12-24T17:07:13.100

@Sathya, please try this command yourself, as it suffers the same error as the OP's concern about "con": ren foo.txt err. "err" is not a reserved device name, but it is reserved nonetheless. :) – JMD – 2010-01-05T16:53:41.087

13

CON is a reserved name in Windows. So are PRN, AUX, NUL, LPT1 and others.

Pablo Santa Cruz

Posted 2009-12-23T18:08:14.827

Reputation: 1 625

2CON is short for console. Open a command prompt window, navigate to a directory with a text file and type "copy file.txt con" It will write the contents of the text file to the console (the command prompt window) – Keltari – 2012-09-12T18:45:41.427

11

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.

maranas

Posted 2009-12-23T18:08:14.827

Reputation: 413

4

This is because it is used to represent the "internal devices". However, you can create this folder using the following command in a command prompt:

C:\>md \\.\e:\con

This folder can't be deleted via right click, delete. You have to use the following command (again in a command prompt):

C:\>rd \\.\e:\con

Source: http://yhisham.blogspot.in/2012/09/mystery-about-con-folder-in-windows.html

user1662177

Posted 2009-12-23T18:08:14.827

Reputation: 41

3

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
  • COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9
  • LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9

Source: The specified device name is invalid at Microsoft Docs.

You can use _con instead.

RafaSashi

Posted 2009-12-23T18:08:14.827

Reputation: 141

@DrZoo: The format improvement was nice.  The statement about filenames being case-insensitive is true, although (arguably) obvious.  Beyond that, your edit was 100% wrong.  (1) NUL *is* a reserved file/directory/device name.  (2) COM0 and LPT0 are not.  (Also, technically, you added them to the lists out of order.)  (3) You deleted a link (that still works fine, more than five years after RafaSashi posted it) because *it might break in the future!*  Huh?  That’s not a valid reason to delete information.  (4) Your copy-and-paste introduced bad grammar. – Scott – 2020-01-20T01:09:04.637

2

You can rename it without using any special software, just the command prompt:

For example:

C:\>echo Test > \\?\C:\con
C:\>type \\?\C:\con
Test
C:\>rename \\?\C:\con test.txt
C:\>type test.txt
Test

After \\?\ the full path should be specified.

Regent

Posted 2009-12-23T18:08:14.827

Reputation: 1 586

0

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:

Error opening folder named NUL Error deleting folder named NUL

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

bwDraco

Posted 2009-12-23T18:08:14.827

Reputation: 41 701

3

You’ve mixed up the terminology a bit. \\.\… is a *Win32 device namespace*, \\?\… is a *Win32 filename (also for folders) namespace*, and \\compname\… is a UNC (network) path.

– Synetech – 2012-09-26T05:02:47.423

@Synetech: Corrected. – bwDraco – 2012-09-26T13:14:09.863

0

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.

Synetech

Posted 2009-12-23T18:08:14.827

Reputation: 63 242

0

copy con is an archaic (MS-DOS) method of creating a text file. For example:

copy con output.txt

So it is a reserved word and cannot be used as a folder name in Windows.

Mehper C. Palavuzlar

Posted 2009-12-23T18:08:14.827

Reputation: 51 093