How to delete files and folters if the path name or file name is too long RELIABLY!


There are quite some solutions listed out there.
What does not work:
 rd /s /q 
or renaming each directory to a short name, which you give up after digging over twenty levels deep.
Various tools which cost money and claim to delete such files or directories failed in some cases I had.
What I did not test yet (had no case to test), but has been reported to work: 7-zip.

An actual working solution is: Using robocopy to mirror an empty folder over the folder which should be deleted. I simplified the job here.
Create a
 delete-long-path.cmd 
file, right-click Edit, and the paste following in:
@echo off
echo I will delete:
echo %*
echo.
echo If that is wrong close this window now, else
pause
mkdir "%temp%\emptyfolder3214321"
robocopy "%temp%\emptyfolder3214321" %* /E /MIR /R:1 /W:0
rd /s /q "%temp%\emptyfolder3214321"
rd /s /q %*
pause
Alternatively download it.

Now drag and drop the directory you cannot delete on that delete-long-path.cmd
Confirm if that what it shows looks OK with the Space key, and then be patient.

A variant is a robocopy command without /E, that will not delete empty subdirectories. Another variant is adding /XJ here, that won't delete everything too.

If you are running Windows XP or Server 2003 you need the Windows Server 2003 Resource Kit Tools from Microsoft.

Here a screen-shot what if may look like when working:
robocopy deleting a too long path

Legal Stuff: This is a private homepage. All "TM" mentioned here belong to their owners and not me. Anyone offended contact me at email-address.