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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -