I mentioned before that you would need to code your own directory enumerations methods as the MS methods will fail if they encounter an error and will not continue the enumeration and there is nothing you can do about it
If I was you I would just forget that the MS methods exist.
See below a simple program that will enumerate through the folders/files.
public static void Main(string[] args)
{
MyGetDirectories("C:\\Users", "*.*");
}
public static void MyGetDirectories(string folderPath, string fileFilter)
{
string[] directories = Directory.GetDirectories(folderPath);
foreach (string directory in directories)
{
try
{
MyGetDirectories(directory, fileFilter);
Console.WriteLine($"{directory}");
}
catch(UnauthorizedAccessException)
{
Console.WriteLine($"Cannot access directory {directory}, skipping diirectory.");
}
catch (Exception)
{
}
}
string[] files = Directory.GetFiles(folderPath, fileFilter);
foreach (string file in files)
{
try
{
FileInfo fileInfo = new FileInfo(file);
Console.WriteLine($"File Name = {file} - File Size = {fileInfo.Length}");
}
catch (UnauthorizedAccessException)
{
Console.WriteLine($"Cannot access file information {file}.");
}
catch (Exception)
{
}
}
}