设计一个程序,实现电脑系统盘符的查找,有偿请教

基于mfc,设计一个程序,实现电脑系统盘符的查找,有偿请教

#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <io.h>

void getDiskInfo()
{
	char rootPath[10] = { 0 };
	int isExist = 0;
	int diskNum = 0;
	int countTotal = 0;
	int type = 0;

	printf("磁盘为:");
	for (char a = 'A'; a <= 'Z'; a++) //获取所有盘符 
	{
		sprintf_s(rootPath, "%c:\\", a);
		//isExist值的类别 0:exist 用来检查目录是否存在,2:write 写权限,4:read 读权限,3:write-read 读写权限
		isExist = _access(rootPath, 0);
		
		if (isExist == 0)
		{
			countTotal++;
			printf("%s\t", rootPath);
		}
	}

	printf("\n硬盘个数为:");
	for (wchar_t a = 'A'; a <= 'Z'; a++) //获取本地硬盘盘符数
	{
		wchar_t diskName[10] = { a, L': ' };
		//type的类别 1:可移动磁盘,2:软盘,3:本地硬盘,4:网络磁盘,5:CD-ROM,6:RAM磁盘
		type = GetDriveTypeW(diskName); 
		if (type == 3) {
			diskNum++;
		}
	}
	printf("%d\n", diskNum);

}
void main()
{
	getDiskInfo();
}

 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps: 问答会员年卡【8折】购 ,限时加赠IT实体书,即可 享受50次 有问必答服务,了解详情>>>https://t.csdnimg.cn/RW5m