The Problem
Windows and even Windows 7, have a problem with paths that are over 260 characters. Basically DOS or command line and Windows Explorer can’t deal with paths this long.
The thing is the problem is not about Windows API, the basic components of Windows, but about the programs that run in Windows. An example of this is that Java doesn’t seem to have the 260 character problem, even on Windows.
So for example Java may create a very deep path and then you try to delete the path or sub-directories and Windows Explorer won’t let you instead giving you some obscure error message.
What can you do
The easiest common thing to do is to move/drag sub-directories up higher and then you can delete them, but this is such a pain.
Then I read somewhere, sorry I don’t know where otherwise I would credit them, who suggested robocopy.exe. This program is free from Microsoft and is a tool to clone a directory – very handy but a slightly long story. The bottom line is that Robocopy doesn’t have a problem with paths over 260 characters.
So how to delete with Robocopy
The simple thing is to mirror an empty directory to the one you want to delete. So imagine you want to delete:
C:\Temp\my really really deep directory
First find or create an empty folder, say:
C:\Temp\EmptyFolder
Then get a copy of robocopy.exe from Microsoft and put it in “C:\Windows\system32” – it may already be there. To check open up a command prompt and run “robocopy”.
To delete your directory run the following:
robocopy "C:\Temp\EmptyFolder" "C:\Temp\my really really deep directory" /MIR
This won’t delete “my really really deep directory” but it should be empty now so you can just delete it in Windows Explorer.