代码如下:
// testdisk.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
ULARGE_INTEGER lpFreeBytesAvailableToCaller = 0;
ULARGE_INTEGER lpTotalNumberOfBytes = 0;
ULARGE_INTEGER lpTotalNumberOfFreeBytes = 0;
TCHAR szRoot[4] = {_T("0")};
int driverFlag = 0;
DWORD allDrives = GetLogicalDrives();
if (allDrives!=0)
{
wchar_t systemDir[255] = {L"0"};
GetSystemDirectory(systemDir, 255);
for(int i=0; i<26; i++)
{
if ((allDrives & 1)==1)
{
wsprintf(szRoot, L"%c:\\", i+'A');
if(GetDriveType(szRoot) == DRIVE_FIXED)
{
char driverName = (char)(i+'A');
if (GetDiskFreeSpaceEx(szRoot, &lpFreeBytesAvailableToCaller, &lpTotalNumberOfBytes, &lpTotalNumberOfFreeBytes))
{
double fTotalNumberOfBytes = (double)lpTotalNumberOfBytes.QuadPart;
double flpTotalNumberOfFreeBytes = (double)lpTotalNumberOfFreeBytes.QuadPart;
double flpfreeBytes = (double)lpTotalNumberOfFreeBytes.QuadPart;
printf("%c %.0f\n",driverName,flpfreeBytes);
}
driverFlag++;
}
}
allDrives = allDrives >> 1;
}
}
system("pause");
return 0;
}