File Info Search

I am looking for a way that I could check the information of a folder and a drive, to show the data size and storage amount (KB, MB, GB). This is so that I can compare the size of a folder to the storage capacity of a disk drive. Anyone know how to do this? Thanks!
Go through every file on the hard drive and sum up the sizes.

Some OSes use indexing to speed this up by pre-caching known sizes, but you have to look at your OS SDK to access that.
Last edited on
If you have a tr2 implementation or can use boost filesystem, the following may be useful. In order to get the space taken by a directory, you would need to use a recursive iterator and sum the file sizes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <filesystem>
#include <iostream>

namespace fs = std::tr2::sys ;

void printSpace( const fs::path& p )
{
    std::cout << p << '\n' ;

    auto si = fs::space(p) ;
    std::cout << "Available: " << si.available ;
    std::cout << "\nCapacity: " << si.capacity ;
    std::cout << "\nFree: " << si.free << '\n' ;
}


int main()
{
    printSpace( "C:" ) ;
}
Last edited on
Topic archived. No new replies allowed.