Sign up ×
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

14 Answers 14

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

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
up vote 48 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

Just drop from Powershell into command by running below:

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

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 ( –  Pierre Arnaud Mar 27 at 6:10

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
Worked for me as well under GNU bash, version 4.1.10(4)-release –  rjzii Sep 22 at 4:13

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. –  Pierre Arnaud Mar 27 at 6:07
All commands or Shift+DEL doesn't work for me, but this does. –  larkee Jul 21 at 12:35
Doesn't really work when you have 10's k's of nested folders –  Julian Knight Sep 11 at 16:39

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

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

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

share|improve this answer

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

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 ( –  Pierre Arnaud Mar 27 at 6:09

Dentrasi's solution is what worked best for me, but I wanted to post the specific steps in a top-level answer.

  1. Download and install the latest stable build of 7zip.
  2. Run the 7zip File Manager (7zfm.exe).
  3. In the 7zip File Manager, navigate so that you can see the name of the folder you want to delete (i.e. you're in the parent folder).
  4. Hold the Shift button down.
  5. Click the "Delete" button, either on your keyboard or in the 7zip File Manager toolbar; make sure you're still holding the Shift key down.
  6. Click the "OK" button; make sure you're still holding the Shift key down.
share|improve this answer
Nice try but still didn't work for me with 10's k's of recursive folders. Only rimraf worked. –  Julian Knight Sep 11 at 16:40
@JulianKnight: Yeah, this approach didn't end working for me 100% of the time, either. I just wanted to mention it because it was among the more straightforward processes, and it at least worked part of the time. The only thing I've found that that has worked 100% of the time is the Powershell + NTFSSecurity module script approach, which I described below. IIRC rimraf failed when called, which is how I got into this mess in the first place. See this Node.js thread for details:… –  AspNyc Sep 14 at 5:38
Yes, there will always be problems like that. In fact it was the Arduino IDE's library installation code that did me in (Java), I accidentally selected the folder containing the libraries as a folder to install a library from and off it went! I killed the process as soon as I realised but already had 10's of k's of folders (damn i7/SSD!) The next main release of NPM is meant to help resolve many of the deep library installation issues for Node as dependencies should be met from a much flatter structure. Still I'm really glad someone put me on to rimraf - easy and free. –  Julian Knight Sep 18 at 8:22
@JulianKnight - Yep, a day or two ago somebody told me that npm3 should help to alleviate these problems by preventing deeply nested dependency folder structures. –  AspNyc Sep 27 at 21:38
Don't know whether it "prevents" but it does treat nested dependencies more sensibly so that if your main app requires library X v1.0 and library Y requires Z which also requires X v1.0, the top level library will be used. Currently Z would install its own version of X. –  Julian Knight Sep 28 at 14:00

I finally found out how to do this via Powershell. Here are the instructions I followed for getting this to work on Windows 7:

  1. Create a new folder called NTFSSecurity in the folder C:\Users\XXXX\Documents\WindowsPowerShell\Modules\NTFSSecurity, where XXXX is your Windows username. Example: if my username was "aspnyc", the new folder would be C:\Users\aspnyc\Documents\WindowsPowerShell\Modules\NTFSSecurity .

  2. Download the File System Security PowerShell Module package - it should be available as a simple ZIP file.

  3. Open up a Powershell console, run Get-Module -ListAvailable and make sure NTFSSecurity shows up somewhere in the list of registered modules.
  4. In the Powershell console, run Import-Module NTFSSecurity .
  5. In the Powershell console, run Remove-Item2 "YYYY" -Recurse , where YYYY is the Windows path to the folder you want to recursively delete (e.g. C:\Potatoes\Badgers\FolderToDelete ).
share|improve this answer

protected by BinaryMisfit 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.