How to run through the folder with subfolders and files and put them in a list of files and a list of directories?
I tried to put only files. I got out, maybe there is a better way?
public List<File> getFileList(String directoryPath, ArrayList<File> files) {
File directory = new File(directoryPath);
File[] filesList = directory.listFiles();
for (File file : filesList) {
if (file.isFile()) {
if (!(file.isDirectory())) {
if (file.getName().substring(file.getName().indexOf(".")).equals(".xml")) {
files.add(file);
}
}
} else if (file.isDirectory()) {
this.getFileList(file.getAbsolutePath(), files);
}
}
return files;
}
I want to have a total of two lists with directories and files.