2011-05-24 81 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

相关问题