Writings mostly about Lotus Notes/Domino...by me :
Jesper Kiaer

Looking for a Notes/Domino developer? I'm available


RSS 2.0 Feed
Bookmark and Share

Annoying Windows bug,feature,limit : Directory name is too long - and the fix.

One day I discovered that some program had created a very deep directory structure on my disc, recursively.

The same 3 folders beneath one of the folders. I then tried to deleted it in the Explorer, but I would get an error "File name is too long". I could not delete any folders.

The problem is that the Explorer has short limit on how long a file/directory name can be, 256 I think.
I tried using DEL from a command prompt, but I would get the same error.

I was of course afraid of the structure of the NTFS file system somehow was messed up

But the actual problem is that NTFS is allowing a much deeper folder structure than the 256 characters, so the structure was OK.

....you just can't delete it again with the standard tools in Windows (XP)

So you need to remove them yourself by creating a program which runs through the folders in recursive manner and deletes folder and files on its way (sorry grandma).

Like this:

import java.io.File;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) {
deleteDir(new File("c:\\badfolder"));
}

public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
//System.out.println()
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;

}
}
}

System.out.println(dir.getName());
return dir.delete();
}
}