Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disk Space? (used/free/total) how do I get this? in C++

Tags:

c++

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

like image 237
HoNgOuRu Avatar asked Sep 19 '09 17:09

HoNgOuRu


People also ask

How do I check free space on my C drive?

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.

Which command displays the amount of free disk space?

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.

What command is use to find the disk capacity and free space of the disk?

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).

How do I see C drive space on Windows Server?

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.


2 Answers

#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

like image 187
Nadir SOUALEM Avatar answered Nov 10 '22 10:11

Nadir SOUALEM


GetDiskFreeSpaceEx win32 API

like image 31
aJ. Avatar answered Nov 10 '22 11:11

aJ.