GetVolumeInformation函数使用记录

函数原型

BOOL GetVolumeInformationA(

in, optional LPCSTR lpRootPathName,

out, optional LPSTR lpVolumeNameBuffer,

in DWORD nVolumeNameSize,

out, optional LPDWORD lpVolumeSerialNumber,

out, optional LPDWORD lpMaximumComponentLength,

out, optional LPDWORD lpFileSystemFlags,

out, optional LPSTR lpFileSystemNameBuffer,

in DWORD nFileSystemNameSize

);

在windows中有两种

普通:GetVolumeInformationA

宽字符版:GetVolumeInformationW

这里我以普通GetVolumeInformationA为例;

先看官方文档解释

官方文档:GetVolumeInformationA 函数 (fileapi.h) - Win32 apps | Microsoft Learn

文档不短,其大概意思就是根据传入的盘符路径,获取盘符的各种信息;

接下来就是测试这个函数的功能;

直接上代码:

环境:vsstudio2019

cpp 复制代码
#include <windows.h>
#include <stdio.h>

int main() {
    char volumeName[MAX_PATH];
    char fileSystemName[MAX_PATH];
    DWORD serialNumber;
    DWORD maxComponentLength;
    DWORD fileSystemFlags;

    // 获取F盘的信息(注意:其中的F填你自己要查询的盘符)
    if (!GetVolumeInformationA("F:\\", volumeName, MAX_PATH, &serialNumber, &maxComponentLength, &fileSystemFlags, fileSystemName, MAX_PATH)) {
        printf("获取F盘信息失败,错误码:%d\n", GetLastError());
        return 1;
    }

    // 输出F盘的相关信息
    printf("盘符F的卷标名称:%s\n", volumeName);
    printf("盘符F的序列号:%lu\n", serialNumber);
    printf("盘符F的文件系统名称:%s\n", fileSystemName);
    printf("盘符F的最大组件长度:%lu\n", maxComponentLength);
    printf("盘符F的文件系统标志:%lu\n", fileSystemFlags);

    return 0;
}

输出如下:

相关推荐
weixin_3077791310 小时前
C++代码实现MATLAB中的fitrtree函数功能
开发语言·c++·算法·matlab
AI wins10 小时前
c++新增頭文件
c++
Uncertainty!!10 小时前
Windows 10 与 Ubuntu 22.04 通过 Samba 共享文件夹
windows·ubuntu·共享文件夹
Shadow(⊙o⊙)10 小时前
仿muduo实现高并发服务器——事件就绪管理Channel.hpp
服务器·c++
by2099910 小时前
哈希表——快速找到数据:冲突、删除与扩容的实现
数据结构·c++·哈希算法·散列表
音草11 小时前
C++ 继承详解:从概念到菱形继承
c++
weixin_3077791311 小时前
C++代码实现MATLAB中的spectralcluster函数功能
开发语言·c++·算法·matlab
xiaoye-duck12 小时前
《C++ 项目:手写大模型接入 SDK》Trae IDE 开发环境搭建与依赖管理
c++·ide·语言模型
百事牛科技12 小时前
如何创建7Z压缩包?Windows下7-Zip操作方法
windows·7-zip