Monday, November 13, 2006

Why cant a folder be named "CON" or "LPT1" in windows?


File/Folder named CON or LPT1 on WINDOWS


G:\>mkdir CON
The directory name is invalid.

G:\>mkdir LPT1
The directory name is invalid.

G:\>mkdir LPT2
The directory name is invalid.

G:\>mkdir LPT9
The directory name is invalid.

Have you ever tried to make a folder or file named CON or LPT1 (in general LPTX X takes 1,2,3,...9)? If not try now and see that you cannot make a folder or file with those names. Have u already done? Read on ...

Why is this so?

Inorder to find out why this doesn't work we have to go back to the age of MS-DOS. Microsoft Disk Operating System (MS-DOS) is a command-line operating system that existed before the advent of GUI OS (Graphical User Interface). Everything from making ,renaming, deleting etc was done using commands. Some of the commands are

COPY Copies one or more files to another location.
DEL Deletes one or more files.
DIR Displays a list of files and subdirectories in a directory.
FIND Searches for a text string in a file or files.
.
.

Let us look more closely to the COPY command. The COPY command usage is as follows:
COPY [options] <source> [options] <destination>
In DOS everything is considered as files, even keyboard and printers. The filename for keyboard is given as "CON" and the printer names are given as "LPT1", "LPT2" etc.. So inorder to copy something from keyboard (our input) the following command is used.

G:\>COPY CON mydata.txt
These lines come in mydata.txt and inorder to stop input press Ctrl+Z
^Z

G:\>COPY mydata.txt LPT1



So now you suppose that a folder or file named "con" could be created and you give a COPY CON command. What is DOS supposed to do? copy the CON file or use the keyboard console as input? Thus an ambiguity arises. So Microsoft has purposely disabled making of files or folders named CON / LPT1 / LPT2 etc. in order to remove this ambiguity.

Could you make a CON or LPT1 .. file on WINDOWS?


Found more invalid names? Let me know .....
Invalid Name List

+ CON
+ LPT1, LPT2, LPT3, LPT4 ... LPT9
+ PRN
+ NUL
+ COM1, COM2, COM3 .... COM9

7 comments:

. said...

AUX is another..

Kirti Ranjan Nayak said...

hey buddy, u wrote con as the device driver for keyboard. But it actually stands for the console.
Some other device files which cannot be used as file names are:
AUX
PRN
LPT1, LPT2,...LPT9
COM1,...COM9

Abhinav said...

All, (Hacker of the World)

I found how to create a folder or file named CON , LPT1 , COM1 etc...

STEP1: goto command prompt

STEP2: type in prompt e:\> "mkdir \\.\e:\con"

STEP3: verify by typing "dir \\.\e:\con"

STEP4: delete the file or folder "rmdir \\.\e:\con"

Cheers,
Abhinav Karnawat
"World in Hand"

Anonymous said...

why use "\\" this please tell me

Navin said...

I guess the first 'backslash' (\)escapes the second one.

Anonymous said...

its becomes an UNC path, so that didnt respect old DOS protocol

Anonymous said...

MD \LPT1\\
MD \Con\\