Windows – How to delete a folder which is nested quite deep and avoid “File name too long”

filenameswindows

Eclipse created a temp folder in one of the directories which is nested quite deep, e.g.

dir1\dir1\dir1\dir1\...

I am unable to delete this folder in Windows via Explorer, the del or rmdir commands, nor the Cygwin 'rm' command. How should I remove this very long folder?

It just keeps saying "File name too long…"

Best Answer

If you are like me and don't like to install additional software to fix a problem like this, I'd go with XQYZ's suggestion and use robocopy to solve the problem. (In my case the problem was created by robocopy in the first place, by copying a directory which had recursive junction points in it without supplying /XJ to robocopy).

To delete the directory tree starting at c:\subdir\more\offending_dir:

The total step-by-step-process is as simple as this:

  1. cd c:\subdir\more to cd into its parent directory.
  2. mkdir empty to create an empty directory.
  3. robocopy empty offending_dir /mir to mirror the empty directory into the offending one.
  4. After some waiting you're done! Finish it up with:
  5. rmdir offending_dir to get rid of the now empty offending directory and
  6. rmdir empty to get rid of your intermediate empty directory.