This question already has an answer here:
- Getting files recursively: skip files/directories that cannot be read? 3 answers
- UnauthorizedAccessException cannot resolve Directory.GetFiles failure [duplicate] 7 answers
I have this for finding files and listing to list .but when it comes to a folder that needs authorized access, it stops. How can I make this skip those folders and carry on?
string[] filetypes = new string[] { "3gp", "avi", "dat", "mp4", "wmv",
"mov", "mpg", "flv", }
try
{
foreach (string ft in filetypes)
{
files.AddRange(dif.GetFiles(string.Format("*.{0}", ft),
SearchOption.AllDirectories));
}
}
catch
{
}