AdvC++ - daty zmian na wektorach, ale pobieramy daty zmian na początku

This commit is contained in:
Sasza Stanczew 2024-04-25 15:52:13 +02:00
parent 36f579a2d1
commit 79f2ec2b85

View file

@ -58,17 +58,17 @@ int main() {
std::cout << "File write time is " << std::asctime(std::localtime(&time)); std::cout << "File write time is " << std::asctime(std::localtime(&time));
}; };
std::vector<fs::path> paths; std::vector<std::pair<fs::path, fs::file_time_type>> paths;
for (const auto& entry : fs::directory_iterator(fs::current_path().string() + "/project")) { for (const auto& entry : fs::directory_iterator(fs::current_path().string() + "/project")) {
if (fs::is_regular_file(entry.path())) { if (fs::is_regular_file(entry.path())) {
paths.push_back(entry.path()); paths.push_back(std::make_pair(entry.path(), fs::last_write_time(entry.path())));
} }
} }
std::sort(paths.begin(), paths.end(), [](fs::path a, fs::path b) {return fs::last_write_time(a) > fs::last_write_time(b);}); std::sort(paths.begin(), paths.end(), [](auto a, auto b) {return ( a > b );});
std::cout << "Last modified file is: " << paths.front() << '\n'; std::cout << "Last modified file is: " << paths.front().first << '\n';
print_last_write_time(std::filesystem::last_write_time(paths.front())); print_last_write_time(std::filesystem::last_write_time(paths.front().first));
std::cout << "files which were longest unmodified: " << paths.back() << std::endl; std::cout << "files which were longest unmodified: " << paths.back().first << std::endl;
print_last_write_time(std::filesystem::last_write_time(paths.back())); print_last_write_time(std::filesystem::last_write_time(paths.back().first));
} }