The Directory.GetFiles method fails when it first encounters a folder in which it does not have permissions.
The method throws a UnauthorizedAccessException (which can be caught), but by the time this is done, the method has already failed / completed.
The code I'm using is below:
try { // looks in stated directory and returns the path of all files found getFiles = Directory.GetFiles( @directoryToSearch, filetype, SearchOption.AllDirectories); } catch (UnauthorizedAccessException) { }
As far as I know, there is no way to check in advance whether a certain folder has certain access rights.
In my example, I search the disk over the network, and when I encounter a root folder for access only, my program crashes.
c # exception-handling unauthorized
Ric Sep 08 '09 at 10:23 2009-09-08 10:23
source share