2个回答
推荐于2017-11-25
展开全部
System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();可以获取所有磁盘的信息。 其中 allDrives[0].Name 就是第一个磁盘的名称
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);
}
}
}
/// 获取本地磁盘
/// </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);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询