I am programing under windows, c++, mfc How can I know disk's format by path such as "c:\". Does windows provide such APIs?
Asked
Active
Viewed 6,825 times
4
-
GetVolumeInformation() can tell you if a volume supports encryption/compression/hardlinks etc. You should use those flags and not the name of the filesystem if you need to make sure the volume supports a specific feature. (Remember NTFS/FAT* are not the only filesystems on windows, even tho they are the only ones supported out of the box) – Anders Aug 10 '09 at 17:20
4 Answers
11
The Win32API function ::GetVolumeInformation is what you are looking for.
From MSDN:
BOOL WINAPI GetVolumeInformation(
__in_opt LPCTSTR lpRootPathName,
__out LPTSTR lpVolumeNameBuffer,
__in DWORD nVolumeNameSize,
__out_opt LPDWORD lpVolumeSerialNumber,
__out_opt LPDWORD lpMaximumComponentLength,
__out_opt LPDWORD lpFileSystemFlags,
__out LPTSTR lpFileSystemNameBuffer, // Here
__in DWORD nFileSystemNameSize
);
Example:
TCHAR fs [MAX_PATH+1];
::GetVolumeInformation(_T("C:\\"), NULL, 0, NULL, NULL, NULL, &fs, MAX_PATH+1);
// Result is in (TCHAR*) fs

Coincoin
- 27,880
- 7
- 55
- 76
3
Yes it is GetVolumeInformation.
TCHAR szVolumeName[100] = "";
TCHAR szFileSystemName[10] = "";
DWORD dwSerialNumber = 0;
DWORD dwMaxFileNameLength = 0;
DWORD dwFileSystemFlags = 0;
if(::GetVolumeInformation("c:\\",
szVolumeName,
sizeof(szVolumeName),
&dwSerialNumber,
&dwMaxFileNameLength,
&dwFileSystemFlags,
szFileSystemName,
sizeof(szFileSystemName)) == TRUE)
{
cout << "Volume name = " << szVolumeName << endl
<< "Serial number = " << dwSerialNumber << endl
<< "Max. filename length = " << dwMaxFileNameLength
<< endl
<< "File system flags = $" << hex << dwFileSystemFlags
<< endl
<< "File system name = " << szFileSystemName << endl;
}

KV Prajapati
- 93,659
- 19
- 148
- 186
2
GetVolumeInformation will give you what you need. It will return the name of the drive format in lpFileSystemNameBuffer.
If you want a nice wrapper around it, you might want to look at Microsoft's CVolumeMaster.

Martin
- 3,703
- 2
- 21
- 43
1
The Win32_LogicalDisk class in WMI has a FileSystem Property that exposes that information.

EBGreen
- 36,735
- 12
- 65
- 85