linux - C++: how can I get the list of folders -
i not familiar c++ c# developer.
in project, need delete folders of 1 week before. in c++, how can list of folders of 1 week before based on current system date time?
i working on eclipse ide running on ubuntu 10.10.
if provide sample of code, great.
thanks in advance , appreciated!
with boost:
#include <boost/foreach.hpp> #include <boost/filesystem.hpp> int main(int, char**) { time_t one_week_ago = std::time(null) - (7 * 24 * 3600); boost::filesystem::directory_iterator dir("/tmp"), end; boost_foreach(const boost::filesystem::path& p, std::make_pair(dir, end)) if(boost::filesystem::is_directory(p)) if(boost::filesystem::last_write_time(p) < one_week_ago) boost::filesystem::remove_all(p); }
or without using boost::foreach
#include <boost/filesystem.hpp> int main(int, char**) { time_t one_week_ago = std::time(null) - (7 * 24 * 3600); boost::filesystem::directory_iterator dir("/tmp"), it, end; for(it = dir; != end; it++) { const boost::filesystem::path& p = *it; if(boost::filesystem::is_directory(p)) if(boost::filesystem::last_write_time(p) < one_week_ago) boost::filesystem::remove_all(p); } }
Comments
Post a Comment