Size of a directory

c, c++, winapi, windows

Solution

As far as I am aware you have to do this with iteration on most operating systems.

You could take a look at boost.filesystem, this library has a recursive_directory_iterator, it will iterate though ever file on the system getting accumulation the size.

http://www.boost.org/doc/libs/1_49_0/libs/filesystem/v3/doc/reference.html#Class-recursive_directory_iterator

include <boost/filesystem.hpp>
int main()
{
    namespace bf=boost::filesystem;
    size_t size=0;
    for(bf::recursive_directory_iterator it("path");
        it!=bf::recursive_directory_iterator();
        ++it)
    {   
        if(!bf::is_directory(*it))
            size+=bf::file_size(*it);
    }   
}

PS: you can make this a lot cleaner by using std::accumulate and a lambda I just CBA

Problem

Is there a way to get the directory size/folder size without actually traversing this directory and adding size of each file in it? Ideally would like to use some library like boost but win api would be ok too.

Original source

Related problems