c++ - 如何在winapi中获取驱动器的文件系统信息?
问题描述
我有像 C:/ D:/ E:/ 这样的磁盘字母,我有像 //./PhysicalDrive0 , //./PhysicalDrive1 这样的路径。
如何获取有关文件系统的信息?
例如:
驱动器 C:/ 是 NTFS 或更好: //./PhysicalDrive0 是 NTFS
请为片段
解决方案
你应该看看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;
}
输出:
推荐阅读
- python - 如何在 macOS 中为 pySerial 确定 Arduino 的端口号
- typo3 - TYPO3 - direct_mail - fe_user - 退订
- regex - Apache mod_rewrite 中的正则表达式
- php - 类“异常”的消息导致 PHP 致命错误
- php - 将文件上传到文件夹不起作用
- python - 程序完成后没有给出 [Finished in xs]
- python-2.7 - 将文件的输出写入 .csv
- excel - Excel 宏循环遍历范围,复制/粘贴(一些复杂性)
- javascript - 为什么反应进度条呈现整个百分比而不是逐渐增加它?
- maven - 带有资源的spring boot应用程序的mvn包,总是重新打包整个应用程序