tags:

views:

249

answers:

3

Disk Space? (used/free/total) how do I get this? in C++... thanks just for reading.

+3  A: 

statvfs for linux.

Zed
+4  A: 

GetDiskFreeSpaceEx win32 API

aJ
More help see at : http://www.codeproject.com/KB/system/system_information.aspx
lsalamon
+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