在c#winform中搜索文件
问题描述:
我正在尝试列出C的所有目录和文件:
I am trying to list all Directory and file of C:
I tryed with
Directory.GetDirectories(dir,"*",SearchOption.AllDirectories)
但它抛出错误
but it throwing error
System.UnauthorizedAccessException was unhandled
Message=Access to the path 'c:\Config.Msi\' is denied.
i希望我的程序继续搜索,但需要验证的文件除外。
i want my program such that it continue its search except that files which required Authentication.
答
为避免这种情况,请不要使用SearchOption.AllDirectories
,而是自己编写所有递归代码:
http://stackoverflow.com/a/172575 [ ^ ]
To avoid this, don't useSearchOption.AllDirectories
, but write all the recursion code yourself:
http://stackoverflow.com/a/172575[^]