In C #, there are methods for getting a list of files to which you can apply the SearchOption.AllDirectories parameter to the input.

Tell me, is it possible to somehow avoid any exceptions (Ignore)?

For example, the program will try to look into the system folder where access is absent.

UPD

My question is not quite double.

The question for which the link is provided describes how to ignore some folders during a recursive traversal.

My question is, is it possible to use SearchOption.AllDirectories and the root of the C drive to ignore all exceptions and return a list of files.

  • one
    try { ... } catch { ... } ? - Mirdin
  • @Mirdin, if I'm not mistaken, it will not work. Since the result of the GetFiles method is a collection => if an exception occurs inside, nothing returns to me, but I would like it to return. It turns out that only handles bypass? - iluxa1810
  • Well, do not request AllDirectories at the root of the disk, or make a recursive function that does not need it (here there was a similar question somewhere) - Mirdin
  • four
    In this lesson there is a code you need - a stand-alone bypass with exception handling: stackoverflow.com/q/554087/106 - andreycha
  • one
    My question is, is it possible to use SearchOption.AllDirectories and the root of the C drive to ignore all exceptions and return a list of files. - no, you can't - Grundy

0