Skip to content

Instantly share code, notes, and snippets.

@hoozh
Created November 29, 2017 05:35
Show Gist options
  • Save hoozh/61109bf4af4265a01893f0555804e7e2 to your computer and use it in GitHub Desktop.
Save hoozh/61109bf4af4265a01893f0555804e7e2 to your computer and use it in GitHub Desktop.
/************************************************************************/
/* check harddisk's free space and used space */
/************************************************************************/
/*
void checkDisk()
{
char systemInfo[256];
memset(systemInfo,0,256);
_ULARGE_INTEGER lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
DWORD serialNumber, maxComponentLength, fsFlags;
TCHAR szFileSystem[12];
TCHAR szVolumeName[24];
TCHAR szRoot[4];
DWORD AllDrives = GetLogicalDrives(); //#include <windows.h>
if (AllDrives == 0)
return ;
char drive;
int cnt = 0;
for(int i=0; i<26; i++)
{
drive = i+'A';
sprintf(szRoot,"%c:\\",drive);
if(GetDriveType(szRoot) == DRIVE_FIXED)
{
cnt = cnt + 1;
printf("\n%s\n",szRoot);
if (!GetVolumeInformation(
szRoot,
szVolumeName,//卷标
sizeof(szVolumeName),
&serialNumber,//卷序列号
&maxComponentLength,
&fsFlags,
szFileSystem,
sizeof(szFileSystem)))
{
printf("Failed to retrieve drive information\n");
}
GetDiskFreeSpaceEx(szRoot, &lpFreeBytesAvailableToCaller, &lpTotalNumberOfBytes, &lpTotalNumberOfFreeBytes);
printf("卷标: %s\n分区类型: %s\n卷序列号: %04X-%04X\n",
szVolumeName,
szFileSystem,
serialNumber >> 16,
serialNumber & 0xFFFF
);
printf("分区总空间大小: %d MB\n",lpTotalNumberOfBytes.QuadPart / (1024 *1024));
printf("分区剩余空间大小: %d MB\n",lpTotalNumberOfFreeBytes.QuadPart / (1024 *1024));
printf("调用者可用的空间大小: %d MB\n",lpFreeBytesAvailableToCaller.QuadPart / (1024 *1024));
sprintf(systemInfo, "%s\n%c:%dMB", systemInfo ,drive, lpFreeBytesAvailableToCaller.QuadPart / (1024 *1024));
}
else
if (GetDriveType(szRoot) == DRIVE_CDROM)
{
printf("\nCD ROM:%s\n",szRoot);
}
else
if (GetDriveType(szRoot) == DRIVE_REMOVABLE)
{
printf("\nRemoveable ROM:%s\n",szRoot);
}
}
printf("\n\n\n%s\n\n",systemInfo);
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment