65

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.

Adam
  • 1,272
Seiyria
  • 1,728

11 Answers11

82

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

Adam
  • 1,272
30

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
Jawa
  • 3,679
gd73
  • 409
5

The SuperDelete open-source command-line tool (GitHub) worked for me after other options failed (Windows 10).

Joshua Fox
  • 567
  • 2
  • 10
  • 23
5

I started typing this problem while trying a multitude of commands, including del /F and rmdir /S (as well as holding shift while deleting to try to bypass the recycle bin). I think that rmdir /S actually deleted all of the files so I was able to proceed with deleting the folders that were leaf nodes, then progressing up the tree a few nodes at a time. Eventually I cleaned them all up, but that was ridiculous.

Seiyria
  • 1,728
5

You can integrate this functionality into the windows shell. My enhancement to Flo's answer was too long for a comment.

I added a Delete command to the Windows context menu.

enter image description here

The delete.reg file adds registry entries to associate folders with the robodelete.bat batch file.

delete.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Delete]

[HKEY_CLASSES_ROOT\Directory\shell\Delete\command]
"Extended"=""
@="\"D:\\Documents\\robodelete.bat\" \"%1\""

robodelete.bat

mkdir c:\empty
robocopy /MIR c:\empty %1
rmdir %1
rmdir c:\empty

Note: You may need to change the paths in both files as per your preferences.

WARNING: There is no way to undo this command. It does not use the recycle bin and does not ask Y/N to confirm before destroying the folder for good!

toddmo
  • 572
  • 1
  • 5
  • 14
3

The best way to do this is to use robocopy, I documented this on my personal blog for you to follow:

http://clintboessen.blogspot.com.au/2014/05/how-to-delete-files-which-exceed-255.html

Clint
  • 31
1

In many cases, CDing into the directory from a command prompt and using DEL will work.

If not, you must work your name UP the directory tree: rename the lowest level folder to a shorter name (e.g. "a"), then the next higher folder name, and so on, until the total path is short enough. By working from bottom to top, you always manipulate names, that have a shorter full path than the final files.

Eugen Rieck
  • 20,637
0

Nice way is to have bootable Linux on pendrive and delete files without problems from live CD os.

0
  • Open administrative command prompt
  • net use z: c:\path
  • del z:\*.*

Tweak accordingly. Z: is just an arbitrary drive letter to map the offending path to. That last delete command will erase the WHOLE directory that you've mapped - so be more specific as needed.

-1

I had also the Same Problem, and i found it myself, Simply Rename the Parent Folder as less as possible. Ex. If our Folder in "D" Drive like D://Folder/Undelete_Folder. Only one thing u have to do is that rename parent Folder name as small as, u can rename it "a". then your location will be D://a/Undelete_folder. and then delete the Parent Folder.

-2

If all else fails

Go the the final Directory in the string. Cut the Files The paste back into the 4th or 5th file in the String. Then [Shift] + [Delete] should do the Trick.

I was skeptical to run the above in elevated command prompt as I was deleting a Test Restore File from a DPM backup.

hope this helps.

Andre
  • 1