如何获取驱动器号和名称(卷标)

2024-04-24

我有一个程序可以告诉我所有硬盘/USB,但它只告诉我驱动器号而不是名称。这是我所拥有的:

DriveInfo[] drives = DriveInfo.GetDrives();
Console.WriteLine("Detected Drives: ");
for(int i = 0; i < drives.Count(); i++)
{
     Console.WriteLine("Drive " + i + ": " + drives[i].Name);
}

return drives;

并打印:

Drive 0: C:\
Drive 1: E:\

但我想要这样的名字

Drive 0: C:\ Local disk
Drive 1: E:\ Kingston USB

我怎样才能得到这个?


您正在寻找VolumeLabel财产:

http://msdn.microsoft.com/en-us/library/system.io.driveinfo.volumelabel.aspx http://msdn.microsoft.com/en-us/library/system.io.driveinfo.volumelabel.aspx

Example:

Console.WriteLine(drives[i].VolumeLabel);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何获取驱动器号和名称(卷标) 的相关文章

随机推荐