为什么无法扫描删除磁盘和所有特殊目录? [英] Why failing to scan a removal disk and all special directory?

查看:66
本文介绍了为什么无法扫描删除磁盘和所有特殊目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜欢这个 - >



Like this -->

private static <fileinfo> GetFiles(string Path)
{
   List<fileinfo> L = new List<fileinfo>();
   DirectoryInfo D = new DirectoryInfo(Path);
   FileInfo F;
   try
   {
      foreach (DirectoryInfo DD in D.GetDirectories())
      {
         foreach(FileInfo FF in DD.GetFiles("*.*"))
         {
            F = new FileInfo(FF.FullName);
            L.Add(F);
         }
         L.AddRange(GetFiles(DD.FullName));
      }
   }
   catch
   {

   }
}

推荐答案

Quote:

为什么失败



如果你真的需要知道,删除try catch块,那么你可以看到异常细节或者如下所示


if you really need to know that, remove the try catch block, then you can see the exception details or do as below

try
{

  //your code 
}catch(Exception ex)
{
   // Log the ex.ToString() or show it as message 
}


因为某些文件夹(以及一些文件夹本身)中的文件受到普通访问权限应用程序的任何访问保护 - 只有管理员才能访问它们。因此,当您尝试读取受保护文件的文件信息时,它会引发访问冲突异常。正如您所看到的那样尝试... catch 阻止没有;只是吞下错误,而是记录或报告它们。
Because there are files in some folders (and some folders themselves) which are protected from any access by "ordinary" access permission applications - only admins can access them. So when you try to read file information for protected files, it throws an access violation exception. As you would have seen if your try...catch block didn;t just "swallow" errors, but logged or reported them instead.


这篇关于为什么无法扫描删除磁盘和所有特殊目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆