您的位置:首页 > 其它

DriveInfo.GetDrives使用错误备忘

2017-01-19 10:57 239 查看
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo info in allDrives)
{
if (info.DriveFormat == "FAT")
{
//Do something...
}
}


错误提示

未处理的异常:  System.IO.IOException: 设备未就绪。

   在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

   在 System.IO.__Error.WinIODriveError(String driveName, Int32 errorCode)

   在 System.IO.DriveInfo.get_DriveFormat()

   在 DriveInfoHelper.Program.Main(String[] args)

改正,访问设备的属性前要判断设备是否就绪

DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo info in allDrives)
{
if (info.IsReady
&& info.DriveFormat == "FAT")
{
//Do something...
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐