views:

1407

answers:

10

OK, this isn't necessarily programming related, but it might have a programmatic solution.

When importing a project into eclipse, it somehow started creating recursive versions of the directory.

Now, when I try to delete anything, I get the message " the file name you specify is too long."

I can't delete it from the command shell. I can't delete it from explorer. I can't do ANYTHING with it. I have no idea how many copies of it Eclipse created. Eclipse was running for like a minute before I realized something was wrong and I cancelled the operation.

I can get the properties of the top level folder, and it says it contains 497 folders.

Question 1: how can I delete all this stuff in Windows?

Question 2: What the hell was eclipse thinking?

A: 

Have you tried deleting it from code?

Alex Reitbort
+1  A: 

As to Q1)

Use subst to short-cirquit the paths:

subst Q: C:\very\long\path\created\by\eclipse
Q:
del *.*

As to Q2)

Long paths are less of a problem in other OSes, and there are Windows API functions that can deal with paths longer than 255 characters, so they just did it, I guess.

Tomalak
my directory list goes. . .dirname -> dirname -> dirname -> . . . about 500 times. I can remap "q" to any part of it, but when I try to delete "q" it has the same issue.
Baltimark
Then go on with the next drive letter. Look here: http://stackoverflow.com/questions/236533/
Tomalak
Ok tomalak, you're saying to keep adding drive letters until I get a path short enough to delete, and then "delete from the bottom", if you will. Similar idea to Ian's. Might be more efficient, time-wise. Thanks.
Baltimark
@Baltimark: Yes, exactly. If such a situation arises for me, which happens once in a while, I usually deal with it using a small recursive VBScript that handles the ugly part for me and keeps track of all the stacked drive letters. For a one-off situation, doing it manually can be enough as well.
Tomalak
A: 

Try using Unlocker. It is used for killing processes holding locks on files, but I think it can force-delete f-ed up files, like you have.

Yuval A
But this tool just removes exclusive locks on files. It can't help if the file path is too long.
Tomalak
Right. Doesn't help.
Baltimark
+4  A: 

If you need to deal with paths longer than MAX_PATH, you'll have to use the Unicode versions of the Windows file APIs (e.g. DeleteFileW) and use the \\?\ prefix. You can write a short program using these APIs to enumerate these directories and delete them.

Charlie
+3  A: 

I had a problem similar to this with Eclipse: trying to import a project using Subclipse, it generated a deeply nested set of directories which I couldn't delete.

I did a couple of things, firstly I edited the directory names down to the shortest length possible (actually I think this was pointless). Secondly, I traversed the directory tree as deeply as possible and then cut and pasted the branch out (which makes it possible to delete the original branch), and then repeated the process.

@Charlie and @Tomalek's solutions look like they might be more elegant. I don't plan on repeating the experience to find out though.

Ian Hopkinson
This might be the most inelegant, but I tried the rest. It took a few minutes, but it solved it. And, that's exactly what happened to me. . .I think I was doing an import -> SVN -> checkout. I'm not going to try to reproduce it to be sure, though.
Baltimark
Glad my experience was of use to you :-)
Ian Hopkinson
A: 

UNLOCKER RULES, DUDE!

I was knocking my head to the wall the whole morning, trying to figure this out.

First of all, I don't know how this softwares can create a so long path... When I do that in .NET an exception is thrown BEFORE creating the path... so...

But I could delete the directory thanks to unlocker.

A: 

i'd faced the same problem using eclipse..! a zillion nested folders got created and it took up more than 500MB space!!!!

i tried a ton of things in windows and nothing worked..

finally i just rebooted using ubuntu and deleted that horrible folder.. just like that.. ubuntu doesn't seem to have any such access restrictions based on filepath length as windows does.. makes life a lot easier.. :)

rachel
A: 
robocopy empty_dir base_nested_dir /purge
Gonsalu
A: 

The fix is simple and free! No need to rename the folders at all.

  1. Download Cygwin for free.

  2. use the command rm -f -r <folder-name> and wait a few moments.

I had a folder of size 1.5 GB with numerous inner folders and it worked!

Haitham Sweilem
A: 

For years i had the issue of system locked files,whenever i wanted to change or delete them windows had given error message that disk is full and it may be write protected,then after a lot of agony i found a very efficient and easy to use software for life time using this link: http://www.longpathtool.com ,this software resolved all such problems and have made my database more efficient to be handled.

Thomas Encole