Is possible to read info about the filesystem 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?
PC Help Center To check what file system your computer is using, first open "My Computer." Then right-click on the hard drive you want to check. In most cases, this is the C: drive. Select "Properties" from the pop-up menu. The file system (FAT32 or NTFS) should be specified near the top of the Properties window.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With