vc 查看硬盘盘符剩余空间

string strtemp = "c:\\123\\456\\789.txt";
	char uuu[2] = {0};
	uuu [0]= strtemp[0];
	CString firstchar = uuu;
	CString strRootPath=firstchar + ":\\";
	/*CString strRootPath="E:\\123.txt";*///带根目录标记的磁盘符号
	DWORD dwSectorsPerCluster=0;//每簇中扇区数
	DWORD dwBytesPerSector=0;//每扇区中字节数
	DWORD dwFreeClusters=0;//剩余簇数
	DWORD dwTotalClusters=0;//总簇数
	if (GetDiskFreeSpace(strRootPath,&dwSectorsPerCluster,&dwBytesPerSector,
		&dwFreeClusters,&dwTotalClusters))
	{
		//m_dwVolSize=dwTotalClusters*dwSectorsPerCluster*dwBytesPerSector;//不能这样,否则越界
		double dd=dwSectorsPerCluster*dwBytesPerSector/(1024.*1024.);
		dd=dd/1024.;
		double m_dFree=dwFreeClusters*dd;//该磁盘剩余容量总大小
		if (m_dFree < 1)
		{
			WriteToLogAndTime("硬盘空间小于1G,请清理空间");
			AfxMessageBox("硬盘空间小于1G,请清理空间");
		}
	}

m_dFree是此文件所在盘符的剩余空间

posted on 2013-08-16 18:09  bbsno  阅读(317)  评论(0编辑  收藏  举报

导航