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?

link|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
feedback

4 Answers

up vote 5 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.

link|improve this answer
2  
Didn't work for me. :( – Andrew Arnott Dec 26 '10 at 1:20
feedback

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

link|improve this answer
I tried a bunch of explorer replacements, but all of them just seemed to pass delete requests to the default explorer mechanism, so I gave up. Never thought to use 7zip as an explorer replacement though. I'll have to give it a try. – Herms Dec 3 '09 at 20:41
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
1  
worked great using shift+Del - 7zip couldn't send long-pathed files to the recycle bin.... – cori Mar 2 '11 at 3:44
feedback

Just drop from Powershell into command by running below:

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

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

link|improve this answer
feedback

protected by Diago Nov 9 '10 at 6:48

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

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