环境
Visual Studio 2019 项目字符编码:Unicode
代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <Windows.h>
void putDrivesType(const char* lpRootPathName)
{
UINT uDriverType = GetDriveTypeA(lpRootPathName);
switch (uDriverType) {
case DRIVE_UNKNOWN:puts("未知的磁盘类型");
break;
case DRIVE_NO_ROOT_DIR: puts("路径无效");
break;
case DRIVE_REMOVABLE: puts("可移动磁盘");
break;
case DRIVE_FIXED: puts("固定磁盘");
break;
case DRIVE_REMOTE: puts("网络磁盘");
break;
case DRIVE_CDROM: puts("光驱");
break;
case DRIVE_RAMDISK: puts("内存映射盘");
break;
default: break;
}
printf("\n");
}
int main()
{
DWORD dwSize = MAX_PATH;
char szLogicalDrives[MAX_PATH] = { 0 };
DWORD dwResult = GetLogicalDriveStringsA(dwSize, szLogicalDrives);
if (dwResult > 0 && dwResult <= MAX_PATH) {
char* szSingleDrive = szLogicalDrives;
while (*szSingleDrive) {
printf("Drive: %s ", szSingleDrive);
putDrivesType(szSingleDrive);
szSingleDrive += strlen(szSingleDrive) + 1;
}
}
return 0;
}
结果
|