Kernel Windows XP

Removing Folder With Reserved Names in Windows

I’ve written a file archiving process in ASP that auto creates the directory structure on the main archive folder. The process uses the first four characters of the file to create the directory. It then proceeds to place the file in that directory. As a result all files with common first four characters are placed in a single directory.

Anyway, one of the files archived had the name LPT199999.csv. The ASP process created the archive directory with the name LPT1 and placed the file in it with no issues at all. The only problem is LPT1 is a reserve-word, and when you try to copy this directory to another, it fails with the following error:

 Copy Reserve Name Folder

When you try to delete the folder named LPT1, you get the following error:

Delete Reserve Name Folder

Fortunately, there is a way to delete the directory and prevent further problems. You need to use a syntax that bypasses the typical reserve-word checks completely. For example, you can possibly remove any directory with a command such as:

RMDIR \\.\driveletter:\path\filename

eg. In my case, I deleted all files in the LPT1 directory and ran the following command to remove the directory:

RMDIR \\.\C:\backupdir\LPT1

That’s it… Too easy!