Saturday, October 20, 2018

Deleting long directory names or deep nested folders

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..."





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:

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

https://superuser.com/questions/256105/how-do-i-delete-a-folder-which-is-nested-quite-deep-and-avoid-file-name-too-lon