Thursday, August 04, 2022

CPP: Windows: GetDiskFreeSpaceExW

CPP: Windows: GetDiskFreeSpaceExW

Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread.
#include <iostream>
#include <iomanip>
#include <Windows.h>
int main()
{
ULARGE_INTEGER FreeBytesAvailableToCaller, TotalNumberOfBytes, TotalNumberOfFreeBytes;
auto ret = GetDiskFreeSpaceExW(L"C:\\", &FreeBytesAvailableToCaller, &TotalNumberOfBytes, &TotalNumberOfFreeBytes);
if (ret) {
auto MB = 1.0 / (1024 * 1024 * 1024);
std::wcout << std::setprecision(4);
std::wcout << "FreeBytesAvailableToCaller: " << FreeBytesAvailableToCaller.QuadPart*MB << std::endl;
std::wcout << "TotalNumberOfBytes(MB): " << TotalNumberOfBytes.QuadPart * MB << std::endl;
std::wcout << "TotalNumberOfFreeBytes: " << TotalNumberOfFreeBytes.QuadPart*MB << std::endl;
return 0;
}
else {
return -1;
}
}

Notes:
- Tested using Visual Studio 2022 (17.2.6) C++ Windows Console template
Reference(s):
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexw

No comments:

Fedora install screen chronicle

Fedora install screen chronicle Below are links to Fedora installation screens. It is interesting to see how it has evolved over time. Fe...