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.

6

11 Answers 11

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

5
  • Since this is part of my workflow often enough, I figured out how to integrate it with the Windows shell. See my answer below. :)
    – toddmo
    Commented Sep 1, 2015 at 20:01
  • Note: this command can take a few seconds or even minutes to finish. So, don't worry and let it do the magic :-)
    – Adil Malik
    Commented Apr 19, 2016 at 20:43
  • Thanks, worked for me. I had to make sure I also killed any process (IIS) that were still holding on to one of the files. Commented Apr 6, 2017 at 13:32
  • Whenever I try to open robocopy.exe a window flashes for a second and then nothing happens. Please help Commented Apr 11, 2018 at 7:04
  • For those that are curious, MIR mirrors the source directory onto the existing directory. Since the source is empty, the destination gets clobbered.
    – n00b
    Commented Dec 20, 2019 at 3:09
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
4
  • 2
    This didn't work for me on the first try for me. However after repeating this procedure a few more folder levels in I was able to get everything deleted.
    – abaldwin99
    Commented Sep 28, 2015 at 12:33
  • 1
    Great solution, worked flawlessly. Simple and effective, thank you! Commented Jan 9, 2016 at 19:38
  • GREAT!! works like a charm!!! no other tools needed. Thanks! Commented Oct 25, 2016 at 12:46
  • This works great, and I would add a point to this, if selecting files from the path doesn't work, you can select a folder somewhere in the middle of the long path and move that folder instead, to a temp folder and then delete both in a similar way. Commented Apr 3, 2017 at 23:21
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.

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!

2
  • Thank you for the warning. I need this in my workflow as well but I'd like to avoid having a nuclear button in my right click menu that lacks a Y/N confirmation. If I get time I'll take a shot at making that adjustment and suggest an edit.
    – abaldwin99
    Commented Sep 28, 2015 at 12:31
  • 1
    @abaldwin99, like this maybe stackoverflow.com/a/1807318/1045881
    – toddmo
    Commented Sep 28, 2015 at 15:52
5

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

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

1
  • 4
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes or disappears.
    – Andrea
    Commented May 19, 2014 at 6:36
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.

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.

2
  • 2
    This is very dangerous for non-power users! There is the potential to wipe a drive if done wrong. Commented Jan 24, 2015 at 13:20
  • Agreed 100%. Definitely proceed with caution on this one. Commented Feb 1, 2015 at 5:11
0

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

-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.

1
  • Not only does this not necessarily work (what if it's still larger, even with the reduction?), but I mentioned explicitly that my folder was in the root of the drive.
    – Seiyria
    Commented Dec 25, 2014 at 14:20
-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.

1
  • This likely won't work because they will still have that long file path for the cut operation.
    – Seiyria
    Commented Aug 27, 2014 at 13:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .