To perform filesystem operations, you should be using the filesystem library. For working with time and duration, you should be using the chrono library. A function that implements the requested functionality has to do the following:
- Check whether the entry indicated by the target path exists and is older than the given duration, and if so, delete it
- If it is not older and it's a directory, iterate through all its entries and call the function recursively:
namespace fs = std::experimental::filesystem;namespace ch = std::chrono;template <typename Duration>bool is_older_than(fs::path const & path, Duration const duration){ auto ftimeduration = fs::last_write_time(path).time_since_epoch(); auto nowduration ...