Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Windows seems to have a length limit on file names when trying to delete, though it won't prevent those files from being created.

Our build process creates a number of temporary files (many build off of a WSDL) that run afoul of this limit. Our ant script is somehow able to delete them when doing a clean, but sometimes I need to delete the workarea directory (where all the temp files go) without actually doing a full clean from ant.

This is the same errors this question, but the answers there don't really work for me as I'm dealing with a directory, not a file, and I don't always know what specific files or subdirectories are causing the problem. And I'm trying to avoid any manual process (other than triggering a single command) to actually delete them.

If I try deleting the directory from Explorer I get the error

Cannot delete [file name]: The file name you specified is not valid or too long.  
Specify a different file name

Trying Remove-Item in powershell gives the following error:

Remove-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
At line:1 char:12
+ Remove-Item  <<<< -force -Recurse <directory>

Does anyone know of any tools or easy ways to get around this delete error without having to manually find the problem files and move/rename them?

share|improve this question
I found the solution just before posting this question, but since others may run into this I decided to post it so that they could find the solution I ran across. –  Herms Dec 3 '09 at 19:24
You are allowed to accept your own answer as correct after a day or so. –  Nifle Dec 3 '09 at 19:48
Oh I know, but generally when I do things like this I leave the question "unanswered" for a while to see if anyone else has a better solution. –  Herms Dec 3 '09 at 20:42

13 Answers 13

Download 7zip, its file manager can delete them. Invaluable if you use something like Cobian Backup, which has a nasty habit of creating long paths...

From comments:

If you're still having trouble make sure you're using shift+del. This is because windows tries to move those files to the Recycle Bin.

share|improve this answer
Thanks - this got rid of a dir tree that went a bit recursive and was too deep for del/rmdir/rm/explorer to remove –  Martin Beckett Aug 24 '10 at 15:47
worked great using shift+Del - 7zip couldn't send long-pathed files to the recycle bin.... –  cori Mar 2 '11 at 3:44
+1 7zip. You have to navigate to the folder, and THEN use shift + Del like @cori said. If you select the Delete option from the context menu, it WILl fail there. shift + Del it! –  Urda Jun 20 '12 at 21:25
7zip didn't work for win7 64, so linux did. –  Erik Friesen May 15 '14 at 20:09
I upvote this because with 7zip you can delete also delete a folder wich contains long nested folders inside. Had my problem with a node_module folder that contained crap tons of nested folder and I wasn't able to remove it. 7zip fixed from the base folder flawlessly. +1 –  Gruber Oct 13 '14 at 23:33
up vote 38 down vote accepted

I believe I've found a way to delete things from cmd. Originally I tried the del command, but that didn't work. Then I remembered rmdir. Doing the following:

rmdir /S /Q <dir>

seems to have worked.

share|improve this answer
Didn't work for me. :( –  Andrew Arnott Dec 26 '10 at 1:20
remember to drop into cmd before you attempt to run rmdir. –  brianpeiris Jul 13 '12 at 13:16
You have to do this in the command prompt. It won't work in PowerShell unless you run it as a command prompt command from PowerShell. –  Mark Rucker May 7 '13 at 13:51
For those who are unable to use this solution I have an alternative solution that worked for me (with too long path/file names): Move the file(s)/directory to C:\ to shorten the path, then delete from there. –  Anders Sandberg Nordbø Sep 16 '13 at 10:38
It is possible to have directories that this solution won't work for, that 7-Zip can delete. I just had this happen to me. –  SamStephens Dec 18 '13 at 16:07

None of the other (free) answers here worked for me, but I found one on another site:

rimraf <dir>

rimraf is a node.js package, so you will need to install node.js which includes npm. Then you can run:

npm install -g rimraf

Then you can run rimraf from the command line.

I found this solution because node.js itself was causing this problem due to the way it nests dependencies.

By the way, rimraf gets its name from the UNIX command rm -rf, which recursively deletes files and folders.

share|improve this answer
+1, just tested rimraf, it is well suited to delete the node_modules directory. –  Magleff Jul 7 '14 at 19:13
You just saved me a lot of headache, sir! Thank you! Adding -f to the rimraf command also helps if the folder contains files. –  Goran_Mandic Jul 14 '14 at 20:43
Thank you so much for this :) –  Julian Aubourg Jul 23 '14 at 12:13
What's funny about this is that I was trying to delete a node_modules directory in windows, and I'm so used to *nix that I was perplexed about how to do it. Of course node itself and rimraf in particular are the answer! Thank you for reminding me! –  laurelnaiad Aug 7 '14 at 2:14
Wha-lah! Great solution (we'll see!). Thanks a ton! A crucial module for anyone experimenting with yeoman generators -- which add many dependencies. Thanks again!!! –  Cody Nov 17 '14 at 21:59

Just drop from Powershell into command by running below:

Cmd /C "rmdir /S /Q <dir>" 
share|improve this answer


This guys duplicate shows mirroring an empty folder over the one you want deleted with robocopy I found it worked even better than seven zip because you can ctrl+shift click on cmd pined to your task bar and remove almost anything with admin access :)

share|improve this answer
Robocopy is what has gotten me into this mess before, and Robocopy can get me out of it. Thanks for pointing out this other question and answer. –  Jay Michaud Jul 25 '14 at 21:05

I suggest Total Commander (shareware, but keeps working after trial period with only a minimal nag start screen). That is the way I allways solve the too long filename issues.

share|improve this answer
Thank the lord I found this. Having issues deleting a node_modules folder because it decides to stupidly nest the directories. –  Alias Aug 14 '14 at 9:27
Well, @Alias, Total Commander makes that issue easier to detect, at least for me. After identifying such problem, chkdsk should solve it. –  Sopalajo de Arrierez Aug 14 '14 at 9:59

I like the cmd solution. Although I want to share another workaround that even works in just Explorer: try to shorten the names of the parent folders before deletion: shorter names will shorten the path. Say, you have this tree structure of the folder:


.. Projects

.. .. Some Awesome Project during spring 2014

.. .. .. Some Activity in the park in the city a friday

.. .. .. .. Bla bla bla bla bla bla bla bla bla bla bla bla

.. .. .. .. .. Actual files with long names, too

In this case you cannot delete the folders, you cannot delete or rename the files neither. If you want to remove the whole folder structure or part of it, you can temporarily rename the parent folders and shorten the path, and then remove the folder. The names can be just letters:


.. Projects

.. .. x

.. .. .. y

.. .. .. .. z

.. .. .. .. .. Actual files with long names, too

In my case I just wanted to remove the whole folder with many subfolders and files. So I didn't care about folders' names.

share|improve this answer
I've written a tiny tool that does just that and put it up to GitHub. github.com/epsitec/Tools-RecursiveDelete –  Pierre Arnaud Mar 27 at 6:07

The tool that I used when I had this problem was FastCopy. I selected Delete All from the dropdown, selected the the directory I wanted to delete, and clicked Delete All.

FastCopy delete dialog screenshot

FastCopy is portable (no install required), and there are 32 bit and 64 bit versions available.

share|improve this answer
If you are looking for a command-line tool, you could use a small tool I've published on GitHub (github.com/epsitec/Tools-RecursiveDelete). –  Pierre Arnaud Mar 27 at 6:10

You can also delete them using their equivalent short name. dir /x will show you them.

share|improve this answer

Cygwin's rm -rf works well on long paths!

share|improve this answer
Actually, it doesn't. –  Oliver Salzburg Oct 4 '14 at 12:31
Cygwin worked for me perfectly! Just did a -rm -rf and all the files got deleted. –  Ranhiru Cooray Oct 23 '14 at 4:42

I've tried all the other answers, but they didn't work (atleast for me).

I came across delinfile and worked quite well and pretty quickly!

It's trial is limited to 3 actions / 15 Days but it's usable if you only wanted to delete a few folders/files:

share|improve this answer

Without installing additional software you can use subst command to temporary create an alias to a long named directory.

e.g. If you want to delete folder C:\Very long directory\that exceed\length limit\blah blah blah\abcde\folder to be deleted you can use the command

subst x: "C:\Very long directory\that exceed\length limit\blah blah blah\abcde"

and then you can delete X:\folder to be deleted in Windows Explorer or in command prompt easily. To remove the temporary drive letter alias use the command

subst x: /d
share|improve this answer

I created a simple java program that uses robocopy to delete the files. The jar is a runnable one. For additional output run it from cmd line.


share|improve this answer
And if you do not want to use Java, you could use this tool I wrote using .NET (github.com/epsitec/Tools-RecursiveDelete). –  Pierre Arnaud Mar 27 at 6:09

protected by Diago Nov 9 '10 at 6:48

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.