Recent Articles / Archives

If folder depth more than 255 character

If you have your directory depth more than 255 characters as created in my previous article, file explorer e.g windows explorer will not be able to delete it showing error it has more length then expected or so. In order to delete those folders which has folder depth more than 255 character, copy paste the code below to your favorite editor, save it with the classname you wish, and change the directory mentioned in the code to the target root directory where you want to apply this repetitive deletion.

import java.io.File;
public class ThousandDirectory {
    public static void main(String[] args) {
        String abc = "D:\\ThousandDirectory";
        String onlyDirectory = "ThousandDirectory";
        File baseDirectory = new File(abc);
        try {
            if (baseDirectory.isDirectory()) {
                for (int i = 0; i < 1000; i++) {
                    if (i != 0) {
                        abc = baseDirectory.getParentFile().getAbsolutePath();
                    }
                    File file = new File(abc);
                    if (file.list().length == 0) {
                        baseDirectory = new File(abc);
                        if (file.delete()) {
                            System.out.println(i);
                        }
                        i--;
                    } else if (file.isDirectory()) {
                        abc = baseDirectory.getAbsolutePath() + "\\" + onlyDirectory;
                        baseDirectory = new File(abc);
                    }
                }

            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

Voila You are done. The directories your file explorer(e.g. windows explorer) could not delete are deleted.

Enjoy your deletion.

January 26, 2011 · Java · No Comments Yet

Folder Depth in NTFS System

One curiosity of creating directory under directory and yet another directory under that led me to write a program in java as:

import java.io.File;
public class ThousandDirectory {
    public static void main(String[] args) {
        String abc = "D:\\ThousandDirectory";
        String onlyDirectory = "ThousandDirectory";
        File baseDirectory = new File(abc);
        if (baseDirectory.mkdir()) {
            for (int i = 0; i < 1000; i++) {
                abc = baseDirectory.getAbsolutePath() + "\\" + onlyDirectory;
                File file = new File(abc);
                if (file.mkdir()) {
                    baseDirectory = new File(abc);
                    //System.out.println(abc);
                }
            }
        }
    }
}

What I found was program was hanged! It didn’t recover. And it looked strange to me that the reason was because OS didn’t support the folder depth level above 255 characters.
There is no official published NTFS file specification...however, under NTFS the directory depth is limited by the 255 character file name limit; directory depth cannot be more that.
Want to know more on other file system will update the same post later.

January 19, 2011 · Java · Comments (1)