does linux provide such a function? Thanks!
does linux provide such a function? Thanks!
on the command lineCode:du -sh dirname
I don't think it's possible to do it directly in C++. You will probably have to write a recursive function to do it.
Next door down...
http://cboard.cprogramming.com/forumdisplay.php?f=9
Moved to Linux Programming.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
get all the files in the dir
do stat() on each file
accumulate the size
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
And use Boost.Filesystem's recursive_directory_iterator to do it. For example, if you're not worried about symlinks, you can do this:
Code:#include <boost/cstdint.hpp> #include <algorithm> #include <boost/filesystem.hpp> #include <boost/bind.hpp> #include <boost/iterators/transform_iterator.hpp> namespace fs = boost::filesystem; boost::uintmax_t dir_size(const fs::path &p) { return std::accumulate( boost::make_transform_iterator(&fs::file_size, fs::recursive_directory_iterator(p)), boost::make_transform_iterator(&fs::file_size, fs::recursive_directory_iterator()), static_cast<boost::uintmax_t>(0)); }
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law