Disk Space? (used/free/total) how do I get this? in C++... thanks just for reading.
To check the total disk space left on your Windows 10 device, select File Explorer from the taskbar, and then select This PC on the left. The available space on your drive will appear under Devices and drives.
Use the df command to show the amount of free disk space on each mounted disk. The usable disk space that is reported by df reflects only 90 percent of full capacity, as the reporting statistics allows for 10 percent above the total available space.
That command is df -H. The -H switch is for human-readable format. The output of df -H will report how much space is used, available, percentage used, and the mount point of every disk attached to your system (Figure 1).
Open the Dashboard. In the navigation pane, click Storage, and then click Hard Drives. In the Hard drives section, select the drive letter that was assigned to the newly added hard disk, and in the task pane, click View the hard drive properties.
#include <sys/statvfs.h>
#include <iostream>
#include <cstring>
using namespace std;
int main( int argc, char *argv[] )
{
struct statvfs fiData;
if( argc < 2 ) {
cout <<"Usage, ./size dir1 dir2 ... dirN\n";
return(1);
}
//Lets loopyloop through the argvs
for( int i= 1 ; i<argc; i++ ) {
if((statvfs(argv[i],&fiData)) < 0 ) {
cout << "\nFailed to stat:" << argv[i];
} else {
cout << "\nDisk: " << argv[i];
cout << "\nBlock size: "<< fiData.f_bsize;
cout << "\nTotal no blocks: "<< fiData.f_blocks;
cout << "\nFree blocks: "<< fiData.f_bfree;
}
}
}
Compilation: g++ -o size file.cpp
Test: ./size dir1 dir2
GetDiskFreeSpaceEx win32 API
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With