How to calculate no of files in a directory in java code examples

private static int calNoOfFiles(String directoryPath)
    {
        File fd = new File(directoryPath);
        if(!fd.isFile())
        {
            String list[] = fd.list();
            for(int i = 0; i < list.length; i++)
            {
                String tempDirPath = directoryPath + fileDelimiter + list[i];
                debug(tempDirPath);
                File ftd = new File(tempDirPath);
                if(ftd.isFile())
                    noOfFiles++;
                if(ftd.isDirectory())
                    calNoOfFiles(tempDirPath);
            }

        }
        return noOfFiles;
    }

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

How to capture finger prints in java

Shallow Copy Deep Copy Java example