0

So I've done extensive research on this and I've realized that GetDirectories will stop returning folders at the point it gets an UnauthorizedAccessException even if you have a try...catch block.

try
{
    foreach (DirectoryInfo directory in parent)
    {
        subDirectories = directory.GetDirectories();
    }
}
catch (Exception e) { }

All the sub-directories will get into sub-directories until we hit the exception and then stop. Are there any solutions to this for my specific code? Thanks!

Lews Therin
  • 3,707
  • 2
  • 27
  • 53
JPhillips
  • 59
  • 1
  • 5
  • 1
    When you get the exception, you exit the try block completely, which means you also exit the loop. Plowing through exceptions is generally bad form, but if that's your intent in this case, you would move the try/catch inside the loop. Though you should at least catch the *specific* exception you can safely handle (or ignore). In your code, you're catching (and ignoring) everything. – Anthony Pegram May 27 '16 at 14:33
  • dude your a legend thank you very much I didn't understand try and catch properly had it in the wrong place many thanks!! – JPhillips May 27 '16 at 14:55

0 Answers0