I am developing a script to scan a certain folder to search for certain files and delete them or move them to another folder, according to some rules that have already answered this question and on this other question .
My idea was to abstract this search, saving all the files found (either to move or to delete) in a list and later to make a decision about the operation, but I do not have much idea how to do a search in a certain folder and all your internal directory tree being found.
private static List<File> listarArquivos(File source, boolean condicao) {
List<File> fileList = new ArrayList<>();
File[] list = source.listFiles();
for (File fl : list) {
if (condicao) {
fileList.add(fl);
System.out.println(fl);
}
}
return fileList;
}
This method only lists subfolders and files in the main directory, but does not list more internal files and folders, how to do this recursively?