Scott Hanselman

Naming a File a Reserved Name in the Windows Vista Operating System

April 06, 2007 Comment on this post [7] Posted in Musings | Programming
Sponsored By

Ah, the Compatibility Sins of the Father. Does anyone else think it's a hoot that you can't have a file called lpt1.png on your system? Or a folder called con?

There's a old story about the .NET CLR team - before they took over an entire Top-Level-Domain as their name, thereby effectively thwarting my own .ORG world domination strategy - where they wanted to call the successor to COM and COM++, "COM3."

Apparently it didn't take long for them to realize that this was a sub-optimal name. Probably about this long:

C:\Users\Scott>md com3
The directory name is invalid.

I'm still not clear, however, why this would be a problem in Vista. It's no doubt "compassionate conservative compatibilityism" (my new phrase of the day) on the part of Microsoft.

Of course, it's because the underlying Win32 APIs for opening a file STILL will accept "COM1" as a file name, as in:

portHandle = CreateFile("COM1",
                  EFileAttributes.Device | EFileAttributes.Overlapped, IntPtr.Zero);

There's even a special way in Windows to refer to Serial Ports larger than COM9 in your code, like this -\\.\COM10.

You see, they only choose to oppress us 9 times, for COM1 to COM9. From then on, we can live footloose and fancy-free.

C:\Users\Scott>md com9
The directory name is invalid.

C:\Users\Scott>md com10

C:\Users\Scott>dir com10
Volume in drive C is 70 GIGS SYSTEM
Volume Serial Number is 98A2-64B2

Directory of C:\Users\Scott\com10

From MSDN:

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 by an extension, for example, NUL.tx7.

CLOCK$ is also a reserved device name.

Good times.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
April 07, 2007 1:27
Wouldn't want to do anything that breaks all of those Visicalc users. ;)
April 07, 2007 6:30
Off topic for just a moment...please forgive:

I'm a regular reader via RSS while I think I saw some chatter about you doing a site redesign, I hadn't "fully loaded" in a while.

Just pulled up this post out of the RSS feed and saw the changes.

Very nice!

The site looks modern, clean and very professionally laid out.

I really like it! Good work, Scott!

Just had to say something.

...and now back to our regular programming...
April 07, 2007 8:24
yeah, it's a -1 for me I'm afraid.
The ads mingle with the link to the comments/postback links a little too much.
I can't work out quite why it seems SO much busier but as a regular web reader (I never reinstalled sharpreader after an os pave) it's hurting me more than the old layout.

Still, you can't please everyone.
April 07, 2007 9:08
I came upon a similar post earlier this week.

In the post, Bob said he'd give $25 to the first person that could send him a screenshot of a folder named con. (The blogger did it as a marketing ploy, basically he paid $25 for an increase in traffic. Smart man.)

I believe it was ultimately accomplished by doing something like this: md com1\

And to delete the same directory: rmdir com1\

Such folders can also be created through UNC paths: mkdir \\.\c:\con
April 07, 2007 16:21
Interesting - I've come across the com and lpt filename issue - normally when trying to delete files and it complains that it is a reserved word and therefore not accepted in the del command (wildcards help as long as you don't have any other files starting with co
Didn't know about the clock one either.
April 07, 2007 23:52
Once I spent more than 1 hour trying to figure out why I couldn't create a MySQL table named "con". =) I found out the hard way...
April 17, 2007 9:11
so, what does "copy con con" do nowadays? Nope, not willing to try it on my machine ;-)

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.