UnauthorizedAccessException when using Directory.GetFiles

假如想象 提交于 2019-12-23 16:03:09

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/1228560/unauthorizedaccessexception-when-using-directory-getfiles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!