I wrote this function and it seemed okey but it fails if there are more than one folders in the current directory and no files. It enters only the first folder and does it job there and ignores the other folders. How can I fix this bug?
public static void getAllFiles(File folder, List<File> result) {
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
result.add(listOfFiles[i]);
}
if (listOfFiles[i].isDirectory()) {
getAllFiles(listOfFiles[i], result);
}
}
}