#include <iostream>
//#include "classAh.h"
#include <atlstr.h>
#include <vector>
#include <string>
using namespace std;
//#define DRIVE_UNKNOWN 0
//#define DRIVE_NO_ROOT_DIR 1
//#define DRIVE_REMOVABLE 2
//#define DRIVE_FIXED 3
//#define DRIVE_REMOTE 4
//#define DRIVE_CDROM 5
//#define DRIVE_RAMDISK 6
int main()
{
vector<string> dir_list{
"C:",
"D:",
"E:",
"F:",
"H:",
"J:",
"J:\\temp\\",
"K:",
"K:\\temp\\",
"K:\\temp",
"C:\\Program Files (x86)\\Baidu\\BaiduPinyin",
"C:\\Program Files (x86)\\Baidu\\BaiduPinyin\\",
};
UINT nType;
for (auto dir : dir_list)
{
nType = GetDriveTypeA(dir.c_str());
if (nType != DRIVE_NO_ROOT_DIR) // DRIVE_NO_ROOT_DIR: 路径无效
{
switch (nType)
{
case DRIVE_FIXED:
cout<< dir<<" " << "硬盘" << endl;
break;
case DRIVE_REMOVABLE:
cout << dir << " " << "移动硬盘" << endl;
break;
case DRIVE_CDROM:
cout << dir << " " << "光盘" << endl;
break;
case DRIVE_RAMDISK:
cout << dir << " " << "RAM盘" << endl;
break;
case DRIVE_REMOTE:
cout << dir << " " << "Remote(Network) drive 网络磁盘" << endl;
break;
case DRIVE_UNKNOWN:
default:
cout << dir << " " << "未知盘" << endl;
break;
}
}
else
{
cout << dir << " " << "未知盘" << endl;
}
}
getchar();
return 0;
}
输出:
C: 硬盘
D: 硬盘
E: 硬盘
F: 未知盘
H: 硬盘
J: 硬盘
J:\temp\ 硬盘
K: 移动硬盘
K:\temp\ 移动硬盘
K:\temp 未知盘
C:\Program Files (x86)\Baidu\BaiduPinyin 未知盘
C:\Program Files (x86)\Baidu\BaiduPinyin\ 硬盘
|