36. Deleting files older than a given date

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:

  1. Check whether the entry indicated by the target path exists and is older than the given duration, and if so, delete it
  2. 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 ...

Get The Modern C++ Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.