views:

154

answers:

1

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)?

+4  A: 

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

Jeff Yates
Agreed, this will most likely perform better than checking every single directory's access permissions before processing it.
Bernhof
@Bernhof: I feel the same way. I considered the alternative of checking permissions, but that would do the work twice for valid directories (once to check and again to parse the folder structure) so I decided it was a lesser option.
Jeff Yates
Thanks, I will also try it with the exception when I searched a non-system base drive. That was a different exception.
Joan Venge