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...
}
}