I wrote code to recursively search a file system from the root and return the full path and name of the file.
Problem:
I am using Windows 7 and the directory 'Documents And Settings' is hidden but is also inaccessible and causes any attempt to list() on that directory to return null.
// Grab the list of files and directories
filesAndDirs = dir.list(); <---------- is null because can not access ' Documents And Settings'
// Quick search of the list for our file
for (String element : filesAndDirs){ <------------------- null thrown here
if (element.equals(searchName)){
System.out.println("FILE FOUND");
foundFlag = true;
return new File(dir, element);
}
I would like to use fileAndDirs = null in order to know if the file I am searching for is never found.
When attempting to list() on a forbidden folder, is there a way to test if a folder is forbidden?
Edited by: Always Learning on Feb 26, 2011 1:18 PM
Edited by: Always Learning on Feb 26, 2011 1:23 PM
Edited by: Always Learning on Feb 26, 2011 1:25 PM