DiskType & Size
A snippet that reports a drive's type and its total, free and available space in megabytes.
Combines the two most common drive queries into one function: GetDriveTypeA names the media (unknown, no root, removable, fixed, remote, CD-ROM or RAM disk) and GetDiskFreeSpaceEx returns the three LARGE_INTEGER values - total capacity, bytes free, and bytes available to the calling user under quota. The example skips the space query for removable and CD-ROM drives where it is meaningless, and prints everything in MB. Use it for the storage summary line in any system-info screen.
#include <Windows.H>
#include <Stdio.H>
//////////////////////////////////////////////////////////////////////
BOOL xSuccess;
LARGE_INTEGER a,b,c;
char xDrive2Check[5];
char PrintInfo[57];
int xDrive;
int DriveLoop;
//////////////////////////////////////////////////////////////////////
int GetDriveInfo(char *);
int main(void)
{
GetDriveInfo("C:\\");
return 0;
}
//////////////////////////////////////////////////////////////////////
int GetDriveInfo(char *xDrive2Check)
{
int xDriveType = GetDriveTypeA(xDrive2Check);
if(xDriveType == 0)
sprintf(PrintInfo,"\nDrive %s (Unknown Type)\n",xDrive2Check);
if(xDriveType == 1)
sprintf(PrintInfo,"\nDrive %s (Has No Root)\n",xDrive2Check);
if(xDriveType == 2)
sprintf(PrintInfo,"\nDrive %s (Removable Disk)\n",xDrive2Check);
if(xDriveType == 3)
sprintf(PrintInfo,"\nDrive %s (Fixed Disk)\n",xDrive2Check);
if(xDriveType == 4)
sprintf(PrintInfo,"\nDrive %s (Remote Network Drive)\n",xDrive2Check);
if(xDriveType == 5)
sprintf(PrintInfo,"\nDrive %s (Cd-Rom Drive)\n",xDrive2Check);
if(xDriveType == 6)
sprintf(PrintInfo,"\nDrive %s (RAM Drive)\n",xDrive2Check);
printf("%s",PrintInfo);
if(xDriveType != 2 && xDriveType != 5)
xSuccess = GetDiskFreeSpaceEx(xDrive2Check,(ULARGE_INTEGER *)&a,(ULARGE_INTEGER *)&b,(ULARGE_INTEGER *)&c);
if(xSuccess)
{
printf("MegaBytes Total %d\n",b.QuadPart/1024/1024);
printf("MegaBytes Free %d\n",c.QuadPart/1024/1024);
printf("MegaBytes Availible To Quota %d\n",a.QuadPart/1024/1024);
}
return 0;
}
//////////////////////////////////////////////////////////////////////