Explorer Bug, Long Path, damaged directories

Long ago, I found something strange in Windows Explorer, which I wanted to retry on Vista today.

In Explorer, first create a very big directory tree, consisting out of small directory names. Now, from the bottom, rename these directories to about 100 characters.

Directory Tree

When you reached the top, try browsing the tree, after some directories it won't allow you to open the directory anymore. You can't select it, it will jump back, you can't rename that one, you can't delete the entire tree at once.

Can not delete tree

You can however to get rid of it, start renaming from the top, to all short names again, until you can delete them.

I realize this has something to do with character limits on paths, but this shouldn't be possible, should it? You can't even delete them properly. Is there a way to prevent this from happening? Or at least be able to clean it up without too much hassle?

I created a small proof of concept, using three .bat files.

  • Extract the zip and run Destroy.bat
  • It will first call Mtree.bat to make a small directory tree, where all directories are named "1".
  • Afterwards it calls calls Rtree.bat to rename the directories to a long name.
Feel free to look at the .bat files with a text editor, to check what it does.

Does anyone know why this is happening? I'd love to know the low-level logic behind this.