Disk Space? (used/free/total) how do I get this? in C++... thanks just for reading.
More help see at : http://www.codeproject.com/KB/system/system_information.aspx
lsalamon
2009-09-19 18:02:27
+1
A:
#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
Nadir SOUALEM
2009-09-19 19:47:51