Recent Articles / Archives

Search/Copy/Move file by extension

I recently had a problem to copy my PDF files to a different folder, to do this I could have used windows file search and select all and copy to a different location. But that’s a slow process and my windows explorer says “not responding” many times as there was above 3K PDFs on my computer. So I thought what if I can write a command line program which searches rigorously to the folders provided and finds all PDFs files for me and let me have a copy option to different folder as well. Initially I wrote a program to find files with “.pdf” extension but after successfully searching PDF files, I made it generic for all extensions provided. One interesting thing I found was the count of all the movies with “.avi” extension in some of my shared computer in my office. That was really interesting. And I thought of providing this to everyone, it would be more fun and useful for the needy as well. So let me share my small work which can be an effective tool for you as well. Download FileUtility.exe
The only thing required is JRE C:\Program Files\Java\JRE folder. For non-java users JRE can be downloaded on http://javadl.sun.com/webapps/download/AutoDL?BundleId=45832.
For Java Developers if you want to reuse the FileUtility API. You can download the JAR and browse the Javadoc and if you want to download Javadoc
Enjoy!!!!!!

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)