I am trying to recursively go through a directory and use GetFiles to return a list of all the files in that directory. Here is my code so far:
public string[] passFiles(string location)
{
string[] files;
try
{
files = Directory.GetFiles(location);
return files;
}
catch (UnauthorizedAccessException)
{
// Code here will be hit if access is denied.
throw;
}
}
But it still gives me an Access Denied error. When I try to leave the catch part blank, it says that all paths must return something, so that's why I put the throw
statement. Any ideas as to why this isn't ignoring the error and going on to the next one?