C # methodsstring drivename ="C:\ \";
System. IO. DriveInfo[] drivers = System. IO. DriveInfo. Getdrives();
foreach (var drive in drivers)
{
if (drivename = = Drive. Name)
Console. WriteLine(drive. Totalfreespace /(1024x768 * 1024x768 *1.0F) + "G");
}
C # can only fetch all of the disks at once, so if you specify a disk, you need to judge and get the Space unit in bytes (byte)
C + + MethodsDWORD64 qwfreebytes, qwfreebytestocaller, qwtotalbytes;
Bresult =GetDiskFreeSpaceEx(TEXT("C:"),
(pularge_integer) &Qwfreebytestocaller,
(pularge_integer) &qwtotalbytes,
(pularge_integer) &qwfreebytes);
If (bresult)
{
cout <<"Use GetDiskFreeSpaceEx"<< Endl;
cout <<"total Byte:"<< qwtotalbytes << Endl;
cout <<"freebyte:"<< qwfreebytes << Endl;
cout <<"Freebyte available:"<< qwfreebytestocaller << Endl ;
cout <<"Free G"<< qwfreebytestocaller /1024x768/ 1024x768 / 1024x768 * 1.0F << Endl;
}
The GetDiskFreeSpaceEx function is explained on MSDN
BOOL WINAPI GetDiskFreeSpaceEx (
_in_opt_ LPCTSTR Lpdirectoryname,
_out_opt_ Pularge_integer lpfreebytesavailable,
_out_opt_ Pularge_integer Lptotalnumberofbytes,
_out_opt_ Pularge_integer Lptotalnumberoffreebytes
);
GetDiskFreeSpaceEx gets the same data unit as Byte