Count files inside a folder or drive
File file = new File("u://");
int count = countFilesInDirectory(file);ilesInDirectory(file);
System.out.println("count" + count);
public static int countFilesInDirectory(File directory) {
int count = 0;
for (File file : directory.listFiles()) {
if (file.isFile()) {
count++;
}
if (file.isDirectory()) {
count += countFilesInDirectory(file);
}
}
return count;
}
Comments