如何用C#获取磁盘名称?

不是卷标

System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();可以获取所有磁盘的信息。 其中 allDrives[0].Name 就是第一个磁盘的名称
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-04-25
/// <summary>
/// 获取本地磁盘
/// </summary>
private void InitListData()
{
DriveInfo[] drivers = DriveInfo.GetDrives();
foreach (DriveInfo driver in drivers)
{
string name = "(" + driver.Name.Substring(0, driver.Name.IndexOf(":") + 1) + ")";
ListViewItem node = new ListViewItem();
if (driver.DriveType != DriveType.CDRom)
{
node.Text = "本地磁盘" + name;
//node.ImageKey = "Hard Drive.ico";
node.Tag = driver.RootDirectory.FullName;
this.LsbSubject.Items.Add(node);
}
else if (driver.DriveType == DriveType.CDRom)
{
node.Text = "光盘" + name;
//node.ImageKey = "CD-ROM Drive.ico";
node.Tag = string.Empty;
this.LsbSubject.Items.Add(node);
}
}
}
相似回答