AdvC++ - zadanie searcher

This commit is contained in:
Sasza Stanczew 2024-04-26 11:05:54 +02:00
parent 81a5ac2f42
commit 1295a11932

View file

@ -14,7 +14,15 @@ namespace rn = std::ranges;
std::vector<fs::path> searchFiles(std::string_view keyWord, const fs::path& dirName) { std::vector<fs::path> searchFiles(std::string_view keyWord, const fs::path& dirName) {
std::vector<fs::path> paths; std::vector<fs::path> paths;
// Write implementation here auto reg_file = [](fs::directory_entry e){return fs::is_regular_file(e);};
for (const fs::directory_entry& entry : fs::directory_iterator(dirName) | std::views::filter(reg_file)) {
std::ifstream file(entry.path());
const auto res = std::find_if(std::istream_iterator<std::string>(file), std::istream_iterator<std::string>{},
[keyWord](const auto& str){ return str == keyWord; });
if(res != std::istream_iterator<std::string>{})
paths.push_back(entry.path());
}
return paths; return paths;
} }