AdvC++ - zadanie z wypisaniem najstarszego i najnowszego pliku

This commit is contained in:
Sasza Stanczew 2024-04-25 15:34:45 +02:00
parent 8b0352bde6
commit 7e5b663eab

View file

@ -50,15 +50,32 @@ int main() {
printPermissionsForDir(); printPermissionsForDir();
// Part 2 unncoment later // Part 2 unncoment later
/*
auto print_last_write_time = [](std::filesystem::file_time_type const& ftime) { auto print_last_write_time = [](std::filesystem::file_time_type const& ftime) {
std::time_t time = std::chrono::system_clock::to_time_t( std::time_t time = std::chrono::system_clock::to_time_t(
std::chrono::file_clock::to_sys(ftime)); std::chrono::file_clock::to_sys(ftime));
std::cout << "File write time is " << std::asctime(std::localtime(&time)); std::cout << "File write time is " << std::asctime(std::localtime(&time));
}; };
std::cout << "Last modified file is: " << *last_modify << '\n';
print_last_write_time(std::filesystem::last_write_time(*last_modify)); fs::path last_mod;
std::cout << "files which were longest unmodified: \n"; fs::path longest;
// Print it here for (const auto& entry : fs::directory_iterator(fs::current_path().string() + "/project")) {
*/ if (fs::is_regular_file(entry.path())) {
if(last_mod == ""){
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::cout << "files which were longest unmodified: " << longest << std::endl;
print_last_write_time(std::filesystem::last_write_time(longest));
} }