In my program, the following are implemented there is a listView in it, I bring out the folders that have certain data in the inside. But some of them are empty. I'm trying to make a check that it does not display empty folders for me in the listView
public static File dir= new File(Environment.getExternalStorageDirectory().getPath()+"/Sales/Archive");
ArrayList<String> theNamesOfFiles = new ArrayList<>();
File[] filelist = dir.listFiles();
for (int i = 0; i < filelist.length; i++) {
long diff = (new Date().getTime() - filelist[i].lastModified()) / 144 / 144 / 144;
Arrays.sort(filelist, Comparator.comparingLong(File::lastModified).reversed());
if (diff < 72)
theNamesOfFiles.add(filelist[i].getName());
}
After some attempts, it turned out that he goes into every file there looking for what I need. But he displays everything the same without them
File Path = new File((new File(ArchiveDir)).getParent());
File[] listFile = Path.listFiles();
for (File file : listFile) {
File[] listFile2 = file.listFiles();
for (File file2 : listFile2){
if (file.isDirectory() && file2.getName().toUpperCase().contains("S")) {
File[] filelist = Path.listFiles();
for (int i = 0; i < filelist.length; i++) {
long diff = (new Date().getTime() - filelist[i].lastModified()) / 144 / 144 / 144;
Arrays.sort(filelist, Comparator.comparingLong(File::lastModified).reversed());
if (diff < 72)
theNamesOfFiles.add(filelist[i].getName());
}
}
}
}