How to get Drive Letter and Name (volume label)

前端 未结 2 1985
旧时难觅i
旧时难觅i 2021-02-08 03:16

I have a program that tells me all the hard disks/ usb\'s, but it only tells me the drive letter not the name. Here is what I have:

DriveInfo[] drives = DriveIn         


        
2条回答
  •  粉色の甜心
    2021-02-08 04:02

    Try this

     try
            {
                DriveInfo[] myDrives = DriveInfo.GetDrives();
    
                foreach (DriveInfo drive in myDrives)
                {
                    Console.WriteLine("Drive:" + drive.Name);
                    Console.WriteLine("Drive Type:" + drive.DriveType);
    
                    if (drive.IsReady == true)
                    {
                        Console.WriteLine("Vol Label:" + drive.VolumeLabel);
                        Console.WriteLine("File System: " + drive.DriveFormat);
    
                    }
                }
            }
            catch (Exception)
            {
    
                throw;
            }
    

提交回复
热议问题