Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get info about disk filesystem?

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?

like image 447
Simon Avatar asked May 24 '11 14:05

Simon


People also ask

How do I know if my hard drive is FAT32 or NTFS?

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.


2 Answers

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);
    }
}
like image 146
Cody Gray Avatar answered Oct 18 '22 21:10

Cody Gray


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.

like image 45
Anton Semenov Avatar answered Oct 18 '22 21:10

Anton Semenov