c++ - Checking files size from current directory -
c++ - Checking files size from current directory -
below function read directory , insert files name (by push_back()) vector
#include <dirent.h> void open(string path){ dir* dir; dirent *pdir; dir = opendir(path.c_str()); while (pdir = readdir(dir)){ vectorforresults.push_back(pdir->d_name); } }
question: how can check size of each file (from current directiory) using boots library?
i found method described on http://en.highscore.de/cpp/boost/filesystem.html
it's e.g.:
boost::filesystem::path p("c:\\windows\\win.ini"); std::cout << boost::filesystem::file_size(p) << std::endl;
could please help how implement boost in open() function? how assign current directory path name variable p , iterate through files names.
does help?
live on coliru
#include <boost/filesystem.hpp> #include <boost/range/iterator_range.hpp> #include <iostream> namespace fs = boost::filesystem; int main() { for(auto& f : boost::make_iterator_range(fs::directory_iterator("."), {})) { if (fs::is_regular(f)) std::cout << fs::file_size(f) << "\t" << f << "\n"; } }
note "."
current directory
c++ boost
Comments
Post a Comment