// 遍历磁盘类型: GetDriveType()#include <iostream>
#include <windows.h>using namespace std;int main()
{char rootPath[10] = {0}, driveType[21] = {0};UINT nType;for(char a = 'A'; a <= 'Z'; a++){sprintf(rootPath, "%c:\\", a);nType = GetDriveType(rootPath);if(nType != DRIVE_NO_ROOT_DIR) // DRIVE_NO_ROOT_DIR: 路径无效{switch(nType){case DRIVE_FIXED:strcpy(driveType, "硬盘");break;case DRIVE_REMOVABLE:strcpy(driveType, "移动硬盘");break;case DRIVE_CDROM:strcpy(driveType, "光盘");break;case DRIVE_RAMDISK:strcpy(driveType, "RAM盘");break;case DRIVE_REMOTE:strcpy(driveType, "Remote(Network) drive");break;case DRIVE_UNKNOWN:default:strcpy(driveType, "未知盘");break;}cout<<rootPath<<"\t"<<driveType<<endl;}}return 0;
}
运行结果:
C:\ 硬盘
D:\ 硬盘
E:\ 硬盘
F:\ 硬盘
G:\ 光盘
H:\ 光盘
Press any key to continue