Microsoft

Remove folders or files with blank or reserved names

Removing files or folders with blank or reserved names can be all but impossible unless you know a few handy command-line tricks. Learn to handle these pesky items on both FAT and NTFS disks.


DOS introduced certain reserved device names, such as COM1, LPT2, and PRN, which identify the system’s first COM port and printer port, respectively. You can use these and other reserved names in certain DOS commands to direct output to the named device. For example, you can direct a text file to the printer using a command similar to TYPE FILE.TXT > PRN.

Unfortunately, It’s possible to create folders with a reserved device name or a blank name. Hackers sometimes create such folders to prevent you from deleting a folder tree on your system or simply as a means of inflicting a change on your computer that you can’t easily undo. If you’re having trouble deleting folders or files with blank or reserved names, whether of your own creation or not, there is an easy way to delete them.

FAT vs. NTFS
If the file or folder resides on a FAT partition, first try using the DEL command from a console to remove the file. The following example would delete the file COM1 from the path C:\Program Files\App\COM1:
DEL \\.\C:\Program Files\App\COM1

If the file or folder resides on an NTFS partition, take another approach. The Windows 2000 Resource Kit tool Rm.exe is a POSIX application that runs under Windows 2000 and allows you to remove folders and files, including those with reserved names. The following command would remove a file named COM1 from the C:\Program Files\App folder:
rm –d “//C/Program Files/App/COM1”

From the sample command above, notice that POSIX uses a path structure that's different from DOS/Windows 2000. Also, POSIX commands are case-sensitive, so enter the path using its actual case.

If you need to remove an entire folder tree, use a command similar to the following, replacing the path with the appropriate path to the folder you want to delete:
rm –r “//C/Program Files/App”

Note that the usage of the sample commands assumes Rm.exe is either in the path or the current folder.

Dealing with blank names
These solutions work fine as long as you can open a console on the path where you need to delete the file. But what if the path includes a folder with a blank name? For example, assume you need to delete the file C:\program files\app\\dir2\\dir4\COM1? Notice that there are folders with blank names between app and dir2, as well as between dir2 and dir4. You can’t use the CD command to change to that folder, because CD won’t recognize the blank folder. In most cases, you can simply use rm –r to remove the entire tree, but sometimes you might need to retain the folder structure and delete only the reserved file. The trick is to use the short filename with CD rather than the long filename.

Each file or folder includes a short name as well as a long name. The long name is what you typically see in Windows and the one you normally use with CD to change paths. However, you can also use the short name to change paths, which in this case lets you traverse the folder with the blank long name. Open a command console and change to the parent folder where the blank folder is located. Issue the command DIR /X to view the short names for all files and folders in the current folder. Then, use CD <shortname>, where <shortname> is the blank folder’s short name, to move to that folder. Repeat the process as needed until you reach the folder where the file resides that you need to delete. Then, use rm, DEL, or other commands as necessary to delete the target file or folder.

Editor's Picks

Free Newsletters, In your Inbox