如何知道某个磁盘的格式(是 FAT32 还是 NTFS)

2022-01-12 00:00:00 winapi c++ mfc

我在windows、c++、mfc下编程如何通过c:"等路径知道磁盘的格式.windows有提供这样的API吗?

解决方案

Win32API 函数 ::GetVolumeInformation 就是你要找的.

来自 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,//这里__in DWORD nFileSystemNameSize);

例子:

TCHAR fs [MAX_PATH+1];::GetVolumeInformation(_T("C:\"), NULL, 0, NULL, NULL, NULL, &fs, MAX_PATH+1);//结果在 (TCHAR*) fs

I am programing under windows, c++, mfc How can I know disk's format by path such as "c:". Does windows provide such APIs?

解决方案

The Win32API function ::GetVolumeInformation is what you are looking for.

From MSDN:

GetVolumeInformation Function

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

相关文章