I am using the following recursive method to list all files and folders within a given directory, however it seems to be listing some files that aren’t visible in Windows Explorer – even when I display hidden and system protected files. I have set the method to scan the C:\\ directory, and it hangs after outputting files in the Boot directory and BOOTSECT.BAK. Well, actually, I don’t think it hangs – it looks like it returns the final array but there are still more Files and no exceptions are thrown!
private static ArrayList<File> recursiveSearch(File dir){
File[] files = dir.listFiles();
ArrayList<File> result = new ArrayList<File>();
for(File file : files)
if(file.isDirectory()){
result.add(file);
ArrayList<File >tempList = recursiveSearch(file);
for(File temp : tempList)
result.add(temp);
}else{
result.add(file);
System.out.println(file.getPath());
}
return result;
}
I know about FileSystemView but in this occassion I can’t use it because I need to apply a custom Filename Filter (which I have excluded from the above, but I have tested and it doesn’t affect the methods output). Any help would be appreciated – thanks in advance
This file (bootsect.bak) is detected as a directory, yet returns a null File array. A workaround is to check that it is instantiated: