Force delete files with a rather large name

62

17

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.

Seiyria

Posted 2014-02-18T01:28:00.077

Reputation: 1 664

do you have any idea how your folder structure got this large i came across the same situation when installing grunt. – eran otzer – 2015-08-18T20:50:52.527

1@eranotzer by using npm. – Seiyria – 2015-08-18T21:01:24.807

i men't did the dependencies in your packages.json where written incorrectly ? – eran otzer – 2015-08-18T21:05:26.670

@eranotzer Yes. Because of how npm@2 worked, every dependency nested its dependencies inside of it. This meant that dependency chains could be arbitrarily long. npm@3 is looking to adjust this behavior. – Seiyria – 2015-08-18T22:01:27.320

If we use Git Path, we can use command rm -rf folder_delete. – Khoa TruongDinh – 2016-10-17T04:15:12.450

Answers

4

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

Posted 2014-02-18T01:28:00.077

Reputation: 1 664

76

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

Flo

Posted 2014-02-18T01:28:00.077

Reputation: 1 198

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 – 2015-09-01T20:01:54.587

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 – 2016-04-19T20:43:37.697

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. – Slick Shinobi – 2017-04-06T13:32:48.910

Whenever I try to open robocopy.exe a window flashes for a second and then nothing happens. Please help – Maulik Modi – 2018-04-11T07:04:15.743

For those that are curious, MIR mirrors the source directory onto the existing directory. Since the source is empty, the destination gets clobbered. – n00b – 2019-12-20T03:09:37.850

29

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

gd73

Posted 2014-02-18T01:28:00.077

Reputation: 399

2This 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 – 2015-09-28T12:33:39.507

1Great solution, worked flawlessly. Simple and effective, thank you! – Caner Öncü – 2016-01-09T19:38:04.973

GREAT!! works like a charm!!! no other tools needed. Thanks! – Prasanth K C – 2016-10-25T12:46:05.477

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. – Narayana Nagireddi – 2017-04-03T23:21:29.177

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

Posted 2014-02-18T01:28:00.077

Reputation: 354

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 – 2015-09-28T12:31:21.613

1

@abaldwin99, like this maybe http://stackoverflow.com/a/1807318/1045881

– toddmo – 2015-09-28T15:52:48.087

4

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

Joshua Fox

Posted 2014-02-18T01:28:00.077

Reputation: 495

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

Posted 2014-02-18T01:28:00.077

Reputation: 31

4While 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 – 2014-05-19T06:36:04.990

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

Posted 2014-02-18T01:28:00.077

Reputation: 15 128

0

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

Dariusz Filipiak

Posted 2014-02-18T01:28:00.077

Reputation: 767

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.

Bradley Forney

Posted 2014-02-18T01:28:00.077

Reputation: 651

2This is very dangerous for non-power users! There is the potential to wipe a drive if done wrong. – Rudi Strydom – 2015-01-24T13:20:01.287

Agreed 100%. Definitely proceed with caution on this one. – Bradley Forney – 2015-02-01T05:11:06.510

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

Rohit R

Posted 2014-02-18T01:28:00.077

Reputation: 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 – 2014-12-25T14:20:50.143

-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

Posted 2014-02-18T01:28:00.077

Reputation: 1

This likely won't work because they will still have that long file path for the cut operation. – Seiyria – 2014-08-27T13:06:00.850