如何获取有关磁盘文件系统的信息?

时间:2011-05-24 14:51:26

标签: c# filesystems .net

是否可以使用.NET C#3.5读取有关物理磁盘的文件系统的信息(例如,如果它被格式化为NTFS,FAT等)?

如果是这样,我应该用哪个类来确定这个?

2 个答案:

答案 0 :(得分:11)

是的,这是可能的。查询DriveFormat propertySystem.IO.DriveInfo class

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

答案 1 :(得分: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课程所有可用属性的列表,请参阅here

相关问题