Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnauthorizedAccessException when using Directory.GetFiles

In the application I am writing, the user has the ability to add some folder to search for some files recursively.

The problem is the files he wants to add to the app might be stored in the base drive like K:. So if he add this drive directly, I get an exception.

Or if he adds C:\, then I get UnauthorizedAccessException where it says:

Access to the path 'C:\System Volume Information' is denied.

How can I just scan where I can scan? And give the ability to scan another non-system drive fully (all directories)?

like image 878
Joan Venge Avatar asked Feb 27 '26 03:02

Joan Venge


2 Answers

Catch the exception, ignore it, and move on to the next directory.

like image 113
Jeff Yates Avatar answered Feb 28 '26 15:02

Jeff Yates


Why does this not work for me then. I try/catch the unauthorizedAccessException and it still just stops the program.

like image 39
DaveP... Avatar answered Feb 28 '26 15:02

DaveP...



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!