开发者

How to get info about disk filesystem?

Is possible to read info about the fil开发者_如何学编程esystem of a physical disk (e.g., if it is formatted as NTFS, FAT, etc.) using .NET C# 3.5?

If so, which class should I use to determine this?


Yes, this is possible. Query the DriveFormat property of the System.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);
    }
}


I think you also may be interesting in GetVolumeInformation function.

[EDIT]
You also can use WMI objects for obtaining such information, for example:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜