Force delete files with a rather large name

I regularly use Node.js to manage dependencies for programs I write, no big deal. Today I ended up with a folder structure like this: enter image description here

Trying to delete any file was met with this error:

The source file name(s) are larger than is supported by the file system. Try moving to a location which has a shorter path name, or try renaming to shorter name(s) before attempting this operation.

It was already in C:\, so it wasn't going to get much shorter.


Solution 1:

Use the Microsoft tool robocopy.exe.

  1. Create a new empty folder, e.g. c:\empty
  2. Then copy that empty folder onto the folder which contains the long filenames which you're trying to delete, e.g. c:\myannoyingfolder. Do this like so in the command prompt:

    robocopy /MIR c:\empty c:\myannoyingfolder

Solution 2:

okay, let's say you want to delete a tree D:\very\long\path, you don't necessarily need to use any tools such as Robocopy.

  1. Go to the root directory of the drive which contains the directory which you can't delete
  2. Create a directory with a single letter name, eg D:\a
  3. Navigate to inside the directory that you want to delete, in this case D:\very\long\path
  4. Select all (Ctrl+A) and Cut (Ctrl-X)
  5. Navigate to the folder you just created
  6. Paste (Ctrl-V)
  7. Now, move up to the root directory and delete the temp folder, in this case D:\a
  8. Then go back and delete the original directory