Delete files and folders with paths too long for Windows to delete

I sometimes find that SVN can checkout files and folders which have a path which is then too long for Windows to delete!

Giving rise to the following error:

Destination Path Too Long: The file name(s) would be too long for the destination folder. You can shorten the file name and try again, or try a location that has a shorter path

How to delete long paths in Windows

As I had Cygwin installed I wrote the following Bash script which will try to delete everything in the current directory, if that fails it will move folders up and rename them to something short until it can delete everything!

rm -rf *
for i in {1..20}; do
  find -mindepth 2 -maxdepth 2 -type d | while read f ; do
    rm -rf "$f" || mv -v "$f" $i-(($j++));
rm -rf *

You can run this multiple times or increase the loop range if you have really deep paths.