File System Type

  • Thread starter Thread starter Dennis C. Drumm
  • Start date Start date
D

Dennis C. Drumm

How can I programmable determine the type of file system a drive uses (FAT,
FAT32, or NTFS)?

Thanks,

Dennis
 
How can I programmable determine the type of file system a drive uses
(FAT,
FAT32, or NTFS)?
Here's a sample console application to do that:

using System;
using System.Runtime.InteropServices;
using System.Text;

namespace TestConsoleApp
{
class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool GetVolumeInformation(string
lpRootPathName,
StringBuilder lpVolumeNameBuffer,
[MarshalAs(UnmanagedType.U4)] int nVolumeNameSize,
[MarshalAs(UnmanagedType.U4)] ref int lpVolumeSerialNumber,
[MarshalAs(UnmanagedType.U4)] ref int lpMaximumComponentLength,
[MarshalAs(UnmanagedType.U4)] ref int lpFileSystemFlags,
StringBuilder lpFileSystemNameBuffer,
[MarshalAs(UnmanagedType.U4)] int nFileSystemNameSize);

static void Main(string[] args)
{
bool bResult;
StringBuilder VolumeName = new StringBuilder(256);
StringBuilder FileSystemName = new StringBuilder(256);
int SerialNumber = -1, MaxComponentLength = -1,
FileSystemFlags = -1;
bResult = GetVolumeInformation(
@"c:\",
VolumeName, VolumeName.Capacity,
ref SerialNumber,
ref MaxComponentLength,
ref FileSystemFlags,
FileSystemName, FileSystemName.Capacity);

Console.WriteLine( "Filesystem: " + FileSystemName.ToString()
);
}
}
}

Greetings,
Wessel
 
Dennis C. Drumm said:
How can I programmable determine the type of file system a drive uses
(FAT, FAT32, or NTFS)?

Thanks,

Dennis

Using System.Management classes...

string logDisk= "c:";
string CIMObject = String.Format("win32_LogicalDisk.DeviceId='{0}'",
logDisk);
using(ManagementObject mo = new ManagementObject(CIMObject))
{
mo.Get();
Console.WriteLine(mo["FileSystem"]);
}

Willy.
 
Thanks,

That was a great help!!

Dennis


Willy Denoyette said:
Dennis C. Drumm said:
How can I programmable determine the type of file system a drive uses
(FAT, FAT32, or NTFS)?

Thanks,

Dennis

Using System.Management classes...

string logDisk= "c:";
string CIMObject = String.Format("win32_LogicalDisk.DeviceId='{0}'",
logDisk);
using(ManagementObject mo = new ManagementObject(CIMObject))
{
mo.Get();
Console.WriteLine(mo["FileSystem"]);
}

Willy.
 
Back
Top