Sometimes Windows Explorer refuses to delete files or folders due to "path too long," invalid characters, or other obscure errors. The ROBOCOPY command can often force-delete these stubborn entries.
The Fix
# 1. Create an empty temporary folder, e.g., on your desktop:
mkdir C:\Users\%USERNAME%\Desktop\EmptyTempFolder
# 2. Use ROBOCOPY to sync the empty folder with the stubborn folder, effectively deleting its contents:
robocopy C:\Users\%USERNAME%\Desktop\EmptyTempFolder C:\Path\To\Stubborn\Folder /mir /z
# 3. Now you should be able to delete the stubborn folder normally:
rmdir /s /q C:\Path\To\Stubborn\Folder
Why it works
ROBOCOPY /mir(mirror) synchronizes two directories, including deleting files in the destination that are not present in the source. By syncing an empty source to the problematic destination, it forces the deletion of all contents, bypassing typical path length limitations.
Verify
- Check the
C:\Path\To\Stubborn\Folderlocation; it should now be empty or completely gone.
Notes
- Requires Administrator privileges.
- CAUTION: Ensure the
C:\Path\To\Stubborn\Folderis correct before runningrobocopy /mir. This command will delete everything in the target folder to match the empty source. - After the
robocopystep, you may need to delete theC:\Path\To\Stubborn\Folderitself manually or usingrmdir /s /q. - Delete the
EmptyTempFolderwhen done.
Techworks Blog