AdvC++ - zadanie searcher
This commit is contained in:
parent
81a5ac2f42
commit
1295a11932
1 changed files with 10 additions and 2 deletions
|
|
@ -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> 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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue