首页 > 解决方案 > 如何在winapi中获取驱动器的文件系统信息?

问题描述

我有像 C:/ D:/ E:/ 这样的磁盘字母,我有像 //./PhysicalDrive0 , //./PhysicalDrive1 这样的路径。

如何获取有关文件系统的信息?

例如:

驱动器 C:/ 是 NTFS 或更好: //./PhysicalDrive0 是 NTFS

请为片段

标签: c++winapi

解决方案


你应该看看GetVolumeInformation(),看看这个 API

一个例子,在这里找到

#include <stdio.h>
#include <Windows.h>

int wmain()
{

      // + 1 is for NULL
      WCHAR volumeName[MAX_PATH + 1] = { 0 };
      WCHAR fileSystemName[MAX_PATH + 1] = { 0 };
      DWORD serialNumber = 0;
      DWORD maxComponentLen = 0;
      DWORD fileSystemFlags = 0;

      if (GetVolumeInformation(
            L"C:\\", L"\\MyServer\MyShare\"
        volumeName,
        sizeof(volumeName),
        &serialNumber,
        &maxComponentLen,
        &fileSystemFlags,
        fileSystemName,
        sizeof(fileSystemName)) == TRUE)
      {
            wprintf(L"GetVolumeInformation() should be fine!\n");
            wprintf(L"Volume Name: %s\n", volumeName);
            wprintf(L"Serial Number: %lu\n", serialNumber);
            wprintf(L"File System Name: %s\n", fileSystemName);
            wprintf(L"Max Component Length: %lu\n", maxComponentLen);
            wprintf(L"File system flags: 0X%.08X\n", fileSystemFlags);
      }
      else
      {
            wprintf(L"GetVolumeInformation() failed, error %u\n", GetLastError());
      }
      return 0;
}

输出:

音量信息


推荐阅读