gpt4 book ai didi

c# - DriveInfo.DriveFormat 上的设备未就绪错误

转载 作者:太空宇宙 更新时间:2023-11-03 20:28:27 25 4
gpt4 key购买 nike

我有检索 NTFS 可移动设备信息的方法:

    private void getdriverinfo()
{
// get the usb flash driver
foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
{
if (driveInfo.DriveType == DriveType.Removable && driveInfo.DriveFormat.Equals("NTFS"))
{
comboBox1.Items.Add(driveInfo.Name);
}
}
if (comboBox1.Items.Count == 0)
{
MessageBox.Show("No Removable Device Found , please plug in the USB drive and make sure it is in NTFS format and retry", "No Device Found!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (comboBox1.Items.Count == 1)
{
comboBox1.Text = comboBox1.Items[0].ToString();
}
else
{
MessageBox.Show(comboBox1.Items.Count + " Removable Devices were found , please choose the device you want to protect");
}
}

private void Form1_Load(object sender, EventArgs e)
{
// get the usb flash driver
getdriverinfo();
}

发生此错误:

System.IO.IOException: The device is not ready.

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

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

at System.IO.DriveInfo.get_DriveFormat()

at USB_Data_Protector.Form1.getdriverinfo()

这在我的笔记本电脑上运行良好,没有错误。当它在虚拟电脑或另一台电脑上运行时,显示此错误。

最佳答案

在访问 DriveFormat 之前,您可以检查以下内容吗? IsReady Property

driveInfo.IsReady

关于c# - DriveInfo.DriveFormat 上的设备未就绪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8997835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com