Windows – delete recursive directory created by robocopy when “The file name is too long”

robocopywindows 7

After running robocopy.exe to backup a C:\Users\ folder without using the /xj switch, I ended up with a recursive directory which was too long. For example, if you run dir /b /s you will receive the following error:

The directory name C:\Users\ … \AppData\Local\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data is too long.

I tried deleting it with rmdir "Application Data" /s but I received the error "The file name is too long"

I've looked at other solutions, but I thought I might be able to use the tool that caused the issue to solve it.

Best Answer

Create an empty directory with mkdir empty, then use robocopy empty\ "Application Data\" /mir" which will remove the whole directory tree. Then issue a rmdir empty and rmdir "Application Data to clean up and you're done.