Thanks for everyones help. I thought that there would be an easy method to use to fix the problem, but it seems that I had to write my own recursive search function.
My method was based on Collin's code, so thanx for the help. Here is the code that I wrote:
public static ArrayList GetFiles(string SearchPath, string FileName)
{
ArrayList TempFileNames = new ArrayList();
try
{
DirectoryInfo DirInfo = new DirectoryInfo(SearchPath);
DirectoryInfo[] SubDirs = DirInfo.GetDirectories();
for (int i = 0; i < SubDirs.Length; i++)
{
TempFileNames.AddRange(GetFiles(SubDirs[i].FullName, FileName));
}
TempFileNames.AddRange(Directory.GetFiles(SearchPath, FileName, SearchOption.TopDirectoryOnly));
}
catch (UnauthorizedAccessException ex)
{
return TempFileNames;
}
catch (DirectoryNotFoundException ex)
{
return TempFileNames;
}
return TempFileNames;
}
I have tested it and it works and ignores the unreadable directories as it should. Hopefully this helps the next guy ;)