AdvC++ - zadanie z datą zmiany, ale na wektorach
This commit is contained in:
parent
7e5b663eab
commit
36f579a2d1
1 changed files with 11 additions and 18 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
|
@ -56,26 +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));
|
||||||
};
|
};
|
||||||
|
|
||||||
fs::path last_mod;
|
std::vector<fs::path> paths;
|
||||||
fs::path longest;
|
|
||||||
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())) {
|
||||||
if(last_mod == ""){
|
paths.push_back(entry.path());
|
||||||
last_mod = entry.path();
|
|
||||||
longest = entry.path();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fs::last_write_time(last_mod) < fs::last_write_time(entry.path())){
|
|
||||||
last_mod = entry.path();
|
|
||||||
}
|
|
||||||
if(fs::last_write_time(longest) > fs::last_write_time(entry.path())){
|
|
||||||
longest = entry.path();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "Last modified file is: " << last_mod << '\n';
|
|
||||||
print_last_write_time(std::filesystem::last_write_time(last_mod));
|
std::sort(paths.begin(), paths.end(), [](fs::path a, fs::path b) {return fs::last_write_time(a) > fs::last_write_time(b);});
|
||||||
std::cout << "files which were longest unmodified: " << longest << std::endl;
|
|
||||||
print_last_write_time(std::filesystem::last_write_time(longest));
|
std::cout << "Last modified file is: " << paths.front() << '\n';
|
||||||
|
print_last_write_time(std::filesystem::last_write_time(paths.front()));
|
||||||
|
std::cout << "files which were longest unmodified: " << paths.back() << std::endl;
|
||||||
|
print_last_write_time(std::filesystem::last_write_time(paths.back()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue