The following compiles OK for me as C++17:
#include <vector>
#include <filesystem>
#include <chrono>
#include <regex>
#include <algorithm>
#include <execution>
namespace fs = std::filesystem;
void remove_old_files(const std::regex& re, const std::string& dir,
size_t ndays) {
std::time_t now =
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::vector<fs::path> delayed_remove;
for (const auto& entry : fs::recursive_directory_iterator(dir)) {
std::smatch result;
std::string name = entry.path().filename().string();
if (std::regex_match(name, result, re)) {
std::tm tm{};
tm.tm_year = std::stoi(result[1].str()) - 1900;
tm.tm_mon = std::stoi(result[2].str()) - 1;
tm.tm_mday = std::stoi(result[3].str());
std::time_t file_date = std::mktime(&tm);
if (file_date < now && now - file_date > ndays * 86400) {
std::cerr << "sheduled to erase:" << entry.path() << '\n';
delayed_remove.push_back(entry.path());
}
}
}
std::for_each(std::execution::par, delayed_remove.begin(),
delayed_remove.end(), [](const auto& p) { fs::remove(p); });
}