简体   繁体   English

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

[英]How to get info about disk filesystem?

Is possible to read info about the filesystem of a physical disk (eg, if it is formatted as NTFS, FAT, etc.) using .NET C# 3.5?是否可以使用 .NET C# 3.5 读取有关物理磁盘文件系统的信息(例如,如果它被格式化为 NTFS、FAT 等)?

If so, which class should I use to determine this?如果是这样,我应该使用哪个 class 来确定这个?

Yes, this is possible.是的,这是可能的。 Query the DriveFormat property of the System.IO.DriveInfo class .查询 System.IO.DriveInfo class 的System.IO.DriveInfo DriveFormat

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

I think you also may be interesting in GetVolumeInformation function.我想你也可能对GetVolumeInformation function 感兴趣。

[EDIT] [编辑]
You also can use WMI objects for obtaining such information, for example:您还可以使用 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   

For list of all avaliable properties of Win32_LogicalDisk class see here .有关Win32_LogicalDisk class 的所有可用属性的列表,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM