2011-05-24 104 views

回答

11

是的,這是可能的。查詢System.IO.DriveInfo classDriveFormat property

public static void Main() 
{ 
    DriveInfo[] allDrives = DriveInfo.GetDrives(); 

    foreach (DriveInfo d in allDrives) 
    { 
     Console.WriteLine("Drive {0}", d.Name); 
     Console.WriteLine("Type: {0}", d.DriveFormat); 
    } 
} 
+0

謝謝,這就是它! – Simon 2011-05-26 10:45:02

+0

我想你的意思是'd.DriveFormat'吧? – SepehrM 2014-06-28 12:56:58

+0

@Sepehr是的,謝謝。我不知道代碼示例發生了什麼。我不是故意要有一堆隨機空間,也不是指「文件類型」。 – 2014-08-17 14:29:14

2

我想你也可以在GetVolumeInformation功能很有趣。

[編輯]
您還可以使用WMI對象獲得這樣的信息,例如:

using System.Management; 
..... 
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\""); 
disk.Get(); 
MessageBox.Show(disk["FreeSpace"] + " bytes"); // Displays disk free space 
MessageBox.Show(disk["VolumeName"].ToString()); // Displays disk label 
MessageBox.Show(disk["FileSystem"].ToString()); // Displays File system type 

對於Win32_LogicalDisk類的所有avaliable屬性列表,請參閱here

+0

'DriveInfo'函數是這個函數的託管包裝器。這意味着P/Invoke和你自己調用這個函數真的沒有什麼理由。 – 2011-05-24 15:09:07

+0

@Cody Gray:是的,你說得對,但是OP可能想要讀取磁盤序列號,據我所知DriveInfo是不可能的 – 2011-05-24 15:18:01