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

8 Answers 8

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
2  
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
13  
worked great using shift+Del - 7zip couldn't send long-pathed files to the recycle bin.... –  cori Mar 2 '11 at 3:44
5  
+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
1  
In addition to SHIFT + DEL, 7-Zip provides the Menu Bar/View/Flat View option which in my case was able to list the directories of a supposedly recursive path when cmd or Explorer didn't show anything. –  dgs Nov 21 '13 at 10:22
2  
7zip didn't work for win7 64, so linux did. –  Erik Friesen May 15 at 20:09
up vote 27 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
14  
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
1  
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

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  
+1, just tested rimraf, it is well suited to delete the node_modules directory. –  Magleff Jul 7 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 at 20:43
    
Thank you so much for this :) –  Julian Aubourg Jul 23 at 12:13
    
@Goran_Mandic No problem. BTW, rimraf doesn't have an -f switch. In fact, its only switch is --help, which you can see by running rimraf --help. –  Jordan Jul 23 at 16:00
    
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! –  stu.salsbury Aug 7 at 2:14

http://superuser.com/a/467814/85034

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 at 21:05

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

share|improve this answer

I suggest Total Commander (shareware, but keeps working after trial period with only a 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 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 at 9:59

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

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.