In .NET 4, there's this Directory.EnumerateFiles() method with recursion that seems handy.
However, if an Exception occurs within a recursion, how can I continue/recover from that and continuing enumerate the rest of the files?
try
{
var files = from file in Directory.EnumerateFiles("c:\\",
"*.*", SearchOption.AllDirectories)
select new
{
File = file
};
Console.WriteLine(files.Count().ToString());
}
catch (UnauthorizedAccessException uEx)
{
Console.WriteLine(uEx.Message);
}
catch (PathTooLongException ptlEx)
{
Console.WriteLine(ptlEx.Message);
}