检查目录是否已就绪System.IO.Directory

时间:2012-11-27 02:08:37

标签: asp.net asp.net-mvc io asp.net-mvc-4

有没有办法检查驱动程序是否准备就绪?

由于我列出了所有目录,例如当它到达DVD时,我得到一个异常,说驱动程序没有准备好。

Thanls很多

@{
try
{
    //Resgata todos os drivers Lógicos do Sistema
    string[] drives = System.IO.Directory.GetLogicalDrives();

    Response.Write("<ul class=\"jqueryFileTree\" style=\"display: none;\">\n");

    //Itera sobre cada driver no array
    foreach(string drive in directoryEntries) {


        //Para cada driver cria um LI A 
        Response.Write("\t<li class=\"directory collapsed\"><a href=\"#\" rel=\"" + drive + "\">" + drive + "</a></li>\n");

        //Resgata subDiretórios de cada driver
        string[] directoryEntries = System.IO.Directory.GetFileSystemEntries(drive); 
    }


}
catch (Exception)
{

    throw;
}
}

非常感谢

1 个答案:

答案 0 :(得分:1)

查看DriveInfo.IsReady属性。

  DriveInfo[] allDrives = DriveInfo.GetDrives();

  foreach (DriveInfo d in allDrives)
  {
      if (d.IsReady == true)
      {
         // do something
      }
   }

可在此MSDN条目中找到更多信息: