c# – 使用getDirectories的UnauthorizedAccessException

c# – 使用getDirectories的UnauthorizedAccessException,第1张

概述大家好,我目前通过此次调用获得了我想要的子目录: foreach (DirectoryInfo dir in parent) { try { subDirectories = dir.GetDirectories().Where(d => d.Exists == true).ToArray(); } c 大家好,我目前通过此次调用获得了我想要的子目录:

foreach (DirectoryInfo dir in parent)      {        try        {          subDirectorIEs = dir.GetDirectorIEs().Where(d => d.Exists == true).ToArray();        }        catch(UnauthorizedAccessException e)        {          Console.Writeline(e.Message);        }        foreach (DirectoryInfo subdir in subDirectorIEs)        {          Console.Writeline(subdir);          var temp = new List<DirectoryInfo>();          temp = subdir.GetDirectorIEs("*",SearchOption.AllDirectorIEs).Where(d => reg.IsMatch(d.name)).Where((d => !d.Fullname.EndsWith("TESTS"))).Where(d => !(d.GetDirectorIEs().Length == 0 && d.Getfiles().Length == 0)).Where(d => d.Getfiles().Length > 3).ToList();          candIDates.AddRange(temp);        }      }      foreach(DirectoryInfo dir in candIDates)      {        Console.Writeline(dir);      }

所以现在我的问题是我的最终列表称为候选人我什么都没得到,因为我得到一个访问问题,因为在try块中我的子目录文件夹中找到了一个名为lost的文件夹.我尝试使用try和catch来处理异常,所以我可以继续做我的检查我实际上不关心这个文件夹,我试图忽略它但我不知道怎么去忽略它我的get目录搜索任何想法?我已经尝试使用.where来做一个过滤器来忽略任何包含文件夹名称的文件夹但是它没有用,它只是在文件夹名称中停止了我的程序.

解决方法 您可以像Microsoft解释的那样使用递归: link. 总结

以上是内存溢出为你收集整理的c# – 使用getDirectories的UnauthorizedAccessException全部内容,希望文章能够帮你解决c# – 使用getDirectories的UnauthorizedAccessException所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1226928.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存