3.4. Getting Free Space

You can find out the maximum size of any drive, along with its available free space, using the GetDiskFreeSpace function. Listing 3.3 demonstrates the use of this function.

Code Listing 3.3. Getting the size and free space on a disk
 // drvsize.cpp #include <windows.h> #include <iostream.h> void main() { BOOL success; unsigned long sectorsPerCluster, bytesPerSector, freeClusters, clusters; // Get disk space for drive C success = GetDiskFreeSpace( "c:\\", &sectorsPerCluster, &bytesPerSector, &freeClusters, &clusters); if (!success) { cout << "Error number: " << GetLastError() << endl; return; } // Output full disk size and free space cout << "Disk size: " << sectorsPerCluster * bytesPerSector * clusters << endl; cout << ...

Get Win32 System Services: The Heart of Windows® 98 and Windows® 2000 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.