import java.io.File;
import java.io.IOException;
public class Utils {
/**
* Count files in a directory (including files in all subdirectories)
* @param directory the directory to start in
* @return the total number of files
*/
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;
}
}
|