I need to get the name of my 开发者_运维问答USB Drive.
Say I rename my USB Drive to "ZeroErrors".
and it is Drive letter "G:\" I want to use the drive letter to get the name of the USB Drive.
Look at the DriveInfo class.
string name = new DriveInfo("g").VolumeLabel;
or for all removable drives:
DriveInfo.GetDrives()
.Where(x => x.DriveType == DriveType.Removable)
.Select(x => x.VolumeLabel)
The following code should do the trick:
DriveInfo drive = new DriveInfo("G:");
Console.WriteLine(drive.VolumeLabel);
This link on MSDN and this on CodeProject should help you to get informations from your drives (included the USB).
But instead of use the letter of the drive, use the reference number.
精彩评论