SearchOption.AllDirectories 并忽略访问错误?
string[] files = Directory.GetFiles(tb_dir.Text, tb_filter.Text, SearchOption.AllDirectories);
我正在尝试搜索目录和所有子目录以查找某些文件。我不断遇到当前代码的错误,第二个它看到无法进入的内容就中断了,
在这个应用程序中,这并不重要,我宁愿它继续前进。有没有办法绕过这个代码,避免每次都转储出来?
谢谢
崩溃893
string[] files = Directory.GetFiles(tb_dir.Text, tb_filter.Text, SearchOption.AllDirectories);
I'm trying to search through a directory and all sub directory to find some file. I keep running into an error with the current code that the second it sees something it can't get into it breaks
In this application that doesn't matter i would rather it just move on. Is there anyway to bypass this code from dumping out everytime?
Thanks
Crash893
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以这样做:
并用以下方式调用它:
当然,你可以将文件列表转换为数组。
您必须添加 try catch 块来处理 UnauthorizedAccessException。
You could do something like this:
and call it with:
You could convert the list of files into an array, of course.
You would have to add try catch blocks to handle the UnauthorizedAccessException.