c++获取所有盘符
#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;
}