如何在给定时间发现可用的任何USB存储设备和/或CD / DVD刻录机(使用C#.Net2.0)。
我想向用户提供可以存储文件以便物理移除的设备选择 - 即不是硬盘驱动器。
发布于 2019-03-20 08:49:35
这是用于检查连接到计算机的任何可移动驱动器或CDRom驱动器的VB.NET代码:
Me.lstDrives.Items.Clear()
For Each item As DriveInfo In My.Computer.FileSystem.Drives
If item.DriveType = DriveType.Removable Or item.DriveType = DriveType.CDRom Then
Me.lstDrives.Items.Add(item.Name)
End If
Next
将此代码修改为等效的ac#并不难,并且可以使用更多的driveType。 来自MSDN:
发布于 2019-03-20 09:57:38
using System.IO;
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.IsReady && d.DriveType == DriveType.Removable)
{
// This is the drive you want...
}
}
DriveInfo类文档在这里:
http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx
https://stackoverflow.com/questions/-100001011
复制相似问题