2013-10-04 3 views
4

나는 모든 하드 디스크/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 

으로 내가이 이름을 얻는 방법 싶어?

+2

@Saravana을 시도, 링크 된 질문은 허용하지 않습니다 대답, 또한 가장 높은 투표를 한 사람은 OP – Habib

답변

10

당신은 VolumeLabel 재산을 찾고 있습니다 :

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

예 :

Console.WriteLine(drives[i].VolumeLabel); 
+2

+1. 요청대로 질문에 답하기 때문에 OP가 찾는 대상도 아닙니다. 예상 출력은 [DriveInfo.DriveType] (http://msdn.microsoft.com/)에서 부분적으로 다루는 실제 드라이브 정보를 찾는 것처럼 보입니다. en-us/library/system.io.driveinfo.drivetype.aspx)) –

3

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; 
     }