Deleting files and folders with reserved names on Windows

A while back, I was on DustPuppy and I did some testing with Dropbox. I was seeing what would happen if I had a file on Dropbox whose filename was a reserved name in the Win32 namespace (NUL, CON, PRN, AUX, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8). Since I couldn’t make one using Windows itself (try it for yourself, it won’t work), I made it on the Dropbox Web interface. It’s a valid filename, after all, it’s just reserved by Win32.

As expected, the file didn’t sync to Windows. I tried this also months ago with files that have illegal characters, and they also did not sync. I suggested that one could use the trick to automatically keep it from syncing on Windows.

With that all figured out, I forgot about it. A few days ago, I logged on to TODD and let Dropbox sync. The folder is mostly shared (TODD uses some separate symlinks) between the two operating systems in a common partition.

I log on to DustPuppy today and see that Dropbox is stuck indexing a file. That’s when I realized: when I synced on TODD, the file would have synced, too! Having a reserved name, it’s almost impossible to delete within Windows. I didn’t want to reboot into Linux, so how do I delete it from within Windows?

Trying to rename a folder to CON produces an error saying that the device name is invalid.

Trying to name a folder CON within Windows. Image from The Windows Club

I remember having to do this before when I did the illegal filename trick. The first thing I tried was through the command line using del. Of course that didn’t work; it’s a Windows utility.

I then tried using the Win32 port of the GNU utility rm. That didn’t work either, probably because it’s a Win32 port.

I don’t have Cygwin or a Linux Virtual Machine installed, but I figured trying to delete the file “over the network” using XP Mode might work. No luck.

Off to the Internet! I came across the Super User thread that helped me out the last time. As directed, I executed
del \\?\C:\My\Path\NUL

It worked! Ha ha! I restarted Dropbox and it stopped trying to index the file. I also took a look at he Microsoft Knowledge Base article that was posted, and it gave a comprehensive list of things to try when a file can’t be deleted.

That’s that.

Unless you’re working with multiple operating systems, you probably won’t run into this problem. But if you do, now you know how to deal with it.

So, why are NUL and the others reserved names? They are aliases to devices, and are accessible from every directory. NUL specifically is analogous to *nix’s /dev/null ; it’s the “bit bucket“. It’s where you redirect a program’s output if you don’t care what happens to it.


`$name' says...

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: