S
S
Sasha Pleshakov2015-11-04 15:03:24
C++ / C#
Sasha Pleshakov, 2015-11-04 15:03:24

How to make a directory search so that it bypasses the system ones?

string[] filesForWork = Directory.GetFileSystemEntries(SelectFolder, file_name.Text, SearchOption.AllDirectories);

This line adds all the files in the directory and subdirectories to an array, but hitting system directories throws an UnauthorizedAccessException. How to bypass system directories?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2015-11-04
@mnepoh

The easiest option is to make your own method instead of SearchOption.AllDirectories, bypass all directories with recursion and bypass exceptions with try-catch.
Here Solution 3: www.codeproject.com/Questions/173054/Ignore-Unauth...
Here is a whole thread with such solutions: stackoverflow.com/questions/172544/ignore-folders-...

S
Stanislav Makarov, 2015-11-04
@Nipheris

Elevate privileges to administrative. Although in this case, you should correctly handle the lack of access to the folder. This is a normal situation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question