Thursday, December 11, 2008

[MSWinOS] Files/folders cannot be created/deleted

Have you ever tried creating folders or files with below names ? If no try now itself, its interesting !
CON
PRN
AUX
NUL
COM1
COM2
COM3
COM4
COM5
COM6
COM7
COM8
COM9
LPT1
LPT2
LPT3
If you simply try create/rename the file/folder using windows xp the file name will not change, remains the created or previous name. On the other hand if you try creating the same in Vista following message will be shown.

You can now try creating by DOS commands in the command line but it will still fail.

OK. So what you think will be wrong with OS ?
MSDN says[^] that
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.

Actually these are the reserved names of device drivers of Microsoft Windows Operating System. thats why OS not permitting to do such a thing.
But what to do forbidden fruit is always the sweetest, you may be thinking of creating or deleting the same. So good news is that the operating system leaves some loop hole for us. Creating the above files/folders can be done using command prompt (start->run->cmd). Below is the syntax for the same,
mkdir
\\.\fullpathnameof folder to be created

for eg:

mkdir \\.\C:\testfolder\nul

Above command will create the forbidden folder 'nul' in the path C:\TestFolder .

Now try deleting the created folder from windows xp/vista it will fail showing below messages,

In XP,

In Vista, We can use the reverse logic for removing the same. See the following syntax,
rd \\.\fullpathnameof folder to be deleted

for eg:

rd \\.\C:\testfolder\nul

Now you please try to create/delete Windows' forbidden folders !

No comments: