How to delete a long path in windows.

Viewed 63741

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?

20 Answers

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.

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.

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.

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

Programmatically you can delete using DeleteFileW and RemoveDirectoryW, and prepending L"\\?\" to the file names. Note that you have to use the W version not the A version of the APIs.

Lol I had a similar problem a few years ago. Due to a bug I created indefinite nesting of folders until the filename got too long.

IIRC, I deleted them programmatically by crawling through the folder structure.

I came across a similar problem and using 7-zip(a third-party software) helped me.

  • Install 7-zip https://www.7-zip.org/
  • Open "7-zip File Manager"
  • Using it, navigate to your folder and change the name of the file/folder you want to delete into a simple one.
  • Delete the file/folder with Shift + Del (which might save you from facing the same problem at the Recycle Bin, which might fail again)

If you already have git installed on your system, then a straightforward way of removing the folder with all its contents, is to open a gitbash window, and then run this command.

$ rm -rf DeleteFolderName

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.

Related