2016-10-04 Update: Microsoft finally allows long paths, provided you are running the latest version of Windows 10; you have to opt-in by editing a group policy for now—maybe by 2050 or so this will be the default, once all the old legacy Windows apps are finally dead!
For some reason, Windows doesn't play well with deep folder hierarchies. Often, when building Drupal projects inside VMs with synced directories, I end up with folders with 10+ levels of hierarchy, and when I try to delete the directory within windows, I get the error "Source path too long" (or "File path too long"). This happens a lot with npm, composer, or other package/dependency managers, and I'm amazed there's no easy workaround... but I figured I'd document what I do here, because I've had to look up the process too many times.
1 - Download robocopy
First, download and install the Windows Server 2003 Resource Kit Tools, which includes a CLI utility,
2 - Use robocopy to move the folders into a deletable folder
cmdor PowerShell, cd into the parent directory of the folder you need to delete.
- Create an empty directory (
- Copy the directory to be deleted into the empty directory (
robocopy empty DELETE_ME /mir).
3 - Delete both directories
rmdir DELETE_ME, then
rmdir empty, and the directory should be gone!
There may be other ways to do this, but I haven't seen any other reliable method. Credit where it's due.