Possible Duplicate:
Ignore folders/files when Directory.GetFiles() is denied access
I'm writing a program that requires finding the files from the specified path, in addition to all subdirectories. Unfortuantely, some folders the program tries to access return an exception because access is denied (eg. certain system files). I figured that putting a try block around it would have the script ignore the folders that give errors and continue, but instead, it turns out that any time an exception comes up, even if it is caught, it prevents ANY files from being saved to the array. Therefore, if were to run this, then display the array filePaths, it will still come up blank. Is there any way to have the open folders/files still copied to the array, while simply skipping the blocked folders, as opposed to skipping the entire operation?
public getFiles(string path)
{
string[] filePaths = {};
string path_ = path;
try
{
filePaths = Directory.GetFiles(path_,"*.*",SearchOption.AllDirectories);
}
catch{}
}