private void Bd()
{
DriveInfo[] MyDrives = DriveInfo.GetDrives();
try
{
foreach (DriveInfo MyDrive in MyDrives)
{
String MyType = "";
switch (MyDrive.DriveType)
{
case DriveType.CDRom:
MyType = "光盘设备";
break;
case DriveType.Fixed:
MyType = "固定硬盘";
break;
case DriveType.Network:
MyType = "网络驱动器";
break;
case DriveType.NoRootDirectory:
MyType = "没有根目录";
break;
case DriveType.Ram:
MyType = "RAM磁盘";
break;
case DriveType.Removable:
MyType = "可移动设备";
break;
case DriveType.Unknown:
MyType = "未知设备";
break;
}
if (MyDrive.DriveType == DriveType.Fixed)
{
String[] MySubItems ={ MyDrive.Name.ToString(),
MyDrive.RootDirectory.ToString(),
MyDrive.DriveFormat.ToString(),
MyType,
MyDrive.VolumeLabel.ToString(),
(MyDrive.TotalSize/1024/1024).ToString()+"M",
(MyDrive.TotalFreeSpace/1024/1024).ToString()+"M",
(MyDrive.AvailableFreeSpace/1024/1024).ToString()+"M"};
ListViewItem MyItem = new ListViewItem(MySubItems);
this.listView1.Items.Add(MyItem);
}
else
{
String[] MySubItems ={ MyDrive.Name,
MyDrive.RootDirectory.FullName,
"",MyType,"","","",""};
ListViewItem MyItem = new ListViewItem(MySubItems);
this.listView1.Items.Add(MyItem);
}
}
}
catch (Exception MyEx)
{
MessageBox.Show(MyEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}