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:
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
.
- Create a new empty folder, e.g.
c:\empty
-
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.
- Go to the root directory of the drive which contains the directory which you can't delete
- Create a directory with a single letter name, eg
D:\a
- Navigate to inside the directory that you want to delete, in this
case
D:\very\long\path
- Select all (Ctrl+A) and Cut (Ctrl-X)
- Navigate to the folder you just created
- Paste (Ctrl-V)
- Now, move up to the root directory and delete the temp folder, in this case
D:\a
- Then go back and delete the original directory