How to delete a long path in windows.

WindowsEclipsePath

Windows Problem Overview


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?

Windows Solutions


Solution 1 - Windows

robocopy empty_dir base_nested_dir /purge

Example: If you have a folder path that's too long such as:

D:\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles

follow these instructions to delete it.

  1. Create an empty folder, such as C:\Users\Name\Desktop\temp.
  2. Open a Command Prompt window.
  3. Type robocopy C:\Users\Name\Desktop\temp D:\BackupFolder /purge

Note: If there are spaces in either path in Step 3, the path must be inclosed by quotation marks.

Solution 2 - Windows

7Zip is the ultimate solution if you are not comfortable with command-line.

  1. Open 7Zip File Manager
  2. Navigate to your file
  3. Shift-Delete your file

Cheers!

Solution 3 - Windows

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.

Solution 4 - Windows

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.

Solution 5 - Windows

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.

Solution 6 - Windows

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!

Solution 7 - Windows

A method mentioned in this Windows Sysinternals forum post by maxaha1 worked.

> I suggest that you work top down. As long as you stay within the same > volume (share), you can usually drag the upper level directories to > new parents, without regard for the contents of the directory being > dragged (ie. and the length / recursion issues it might have). So > you take a directory maybe 4 or 5 levels down your problem path, and > drag it to the root. Then delete the original path that now only > contains a few levels. Ideally, work to keep the longest path to less > than 250 chars (includes filenames). I'm doing a system migration at > the moment, and we have some users with 340+ char paths which dont > copy without this method. I've tried subst's, recursive net use's, > recursive scripts, etc.. Unfortunately, users seem to be able to > create things that befuddle the best coders, admins etc..

Create new folders and just drag-and-drop, several folders down from the top each time (and delete them) until you get it all cleaned up.

Solution 8 - Windows

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

Solution 9 - Windows

The previous three responses are obviously spam (for a payware demo). If you want a free one-click solution, see here:

http://www.osmstudios.com/Display.asp?Page=pathtoolong

Which probably employs the 3-line Java from further up this thread.

-fm

Solution 10 - Windows

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.

Solution 11 - Windows

Someone above already posted a reference to "rimraf", but let me add more details. If you have Node installed on your system, then simply use the rimraf module (it can be installed on your Path). This is by far the easiest way to delete things on a Windows system in the most non-trivial of cases. It isn't so much that rimraf is awesome, actually, it's because Node.js handles filesystems at the device kernel level. If you look at the 'fs' module source code for Node, you'll see code such as this. In essence, Node.js handles filesystems much better than even Git for Windows does i.e. there is a bug using git clean -fdx on Windows that doesn't delete folders with long pathnames.

Solution 12 - Windows

MIR (mirror a complete directory tree )option worked for me in windows and window network paths as well.. > robocopy empty_dir <foldertobedeleted> /MIR

  • Just create an empty directory, and tell robocopy to purge everything in the target directory which isn't in the empty directory

output would be like this..

enter image description here>

Solution 13 - Windows

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.

Solution 14 - Windows

I wasn't really happy with any of the solutions posted here and in other places (robocopy, 7zip, subst, shady spyware) so I've rolled my own small command line tool.

It can delete a file or an entire directory recursively. Maybe in the future I'll add more options.

The tool is called SuperDelete and you can get it from the releases page page GitHub.

Solution 15 - Windows

Okay I tried searching for a solution for this and I found one of the easiest solution for windows users

  1. Install Mobaxterm

  2. Open mobaxterm. Go to the directory you wish to delete(using cd) and run the following command

    rm -rf directoryname

All the folder, sub folders which windows was complaining about deleting will now be deleted

Solution 16 - Windows

Its quite annoying that in 2016 this still presents us Windows users a problem when Linux solved this years ago. It's made even more annoying when its do easy to do in Java.

We should use the Change.org to petition MS to include this ability. It can't be hard. If they are worried about backwards compatibility why not just have a Strict mode that admins can turn on or off. At least give us the warning but then allow us to delete it anyway. GRRRRR [/rant]

If you are running Java on your machine you might find this code helpful:

import java.io.File;

public class Delong {

	public static void main(String[] args) {
    	File file = new File("F:\\YourDirectory\\YourFile");
    	boolean result = deleteDirectory(file);
    	
    	if(result)
    		System.out.println("Deleted");
    	else
    		System.out.println("Failed");
	}//end main
	
	/**
	 * Force deletion of directory
	 * @param path The path you want to delete
	 * @return True if it worked;
	 */
	static public boolean deleteDirectory(File path) {
	    if (path.exists()) {
	        File[] files = path.listFiles();
	        for (int x = 0; x < files.length; x++) {
	            if (files[x].isDirectory()) 
	                deleteDirectory(files[x]);
	             else 
	                files[x].delete();
	        }//end for
	    }///end if
	    return (path.delete());
	}//endDeleteDirectory

}//end class

Solution 17 - Windows

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)

Solution 18 - Windows

You can use "Cygwin" with the command "rm --force --recursive PATH" or short "rm -fr PATH".

Solution 19 - Windows

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

Solution 20 - Windows

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBaltimarkView Question on Stackoverflow
Solution 1 - WindowsgonsaluView Answer on Stackoverflow
Solution 2 - WindowsSwanidhiView Answer on Stackoverflow
Solution 3 - WindowsIan HopkinsonView Answer on Stackoverflow
Solution 4 - WindowsTomalakView Answer on Stackoverflow
Solution 5 - WindowsCharlieView Answer on Stackoverflow
Solution 6 - WindowsHaitham SweilemView Answer on Stackoverflow
Solution 7 - WindowsIzzy WeirdView Answer on Stackoverflow
Solution 8 - WindowsrachelView Answer on Stackoverflow
Solution 9 - WindowsF.M.View Answer on Stackoverflow
Solution 10 - WindowsJohnView Answer on Stackoverflow
Solution 11 - WindowslateralpunkView Answer on Stackoverflow
Solution 12 - WindowsRam GhadiyaramView Answer on Stackoverflow
Solution 13 - WindowsZestyView Answer on Stackoverflow
Solution 14 - WindowsMarcel N.View Answer on Stackoverflow
Solution 15 - WindowsPratik ShelarView Answer on Stackoverflow
Solution 16 - WindowsAndrew SView Answer on Stackoverflow
Solution 17 - WindowsUpulie HanView Answer on Stackoverflow
Solution 18 - Windowsuser2814648View Answer on Stackoverflow
Solution 19 - WindowsMickey PuriView Answer on Stackoverflow
Solution 20 - WindowsYuval AdamView Answer on Stackoverflow