UnauthorizedAccessException cannot resolve Directory.GetFiles failure [duplicate]
This question already has an answer here: Ignore folders/files when Directory.GetFiles() is denied access 8 answers Directory.GetFiles method fails on the first encounter with a folder it has no access rights to. The method throws an UnauthorizedAccessException (which can be caught) but by the time this is done, the method has already failed/terminated. The code I am using is listed below: try { // looks in stated directory and returns the path of all files found getFiles = Directory.GetFiles( @directoryToSearch, filetype, SearchOption.AllDirectories); } catch (UnauthorizedAccessException) { }