The following static method returns a total number of files in a directory, including files in sub directories:
/**
* Counts total number of files in a directory, including sub directories
* @param dir the directory
* @return total number of files
*/
public static int countFilesInDirectory(File dir) {
int totalFiles = 0;
File[] listFiles = dir.listFiles();
if (listFiles != null && listFiles.length > 0) {
for (File file : listFiles) {
if (file.isFile()) {
totalFiles++;
} else {
totalFiles += countFilesInDirectory(file);
}
}
}
return totalFiles;
}

Big enthusiast on this blog, a lot of your blogposts have definitely helped me out. Looking forward to updates!
thanks for share!