有没有办法检查驱动程序是否准备就绪?
由于我列出了所有目录,例如当它到达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;
}
}
非常感谢
答案 0 :(得分:1)
查看DriveInfo.IsReady属性。
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.IsReady == true)
{
// do something
}
}
可在此MSDN条目中找到更多信息: