Add function to check if a file contains a string

This commit is contained in:
Georg Hagen
2025-06-06 14:34:35 +02:00
parent 746df316f6
commit 21e6740d38
2 changed files with 21 additions and 0 deletions

View File

@@ -240,4 +240,23 @@ namespace OpenVulkano
}
return fileName;
}
bool FsUtils::FileContains(const std::filesystem::path& path, const std::string_view& searchString)
{
std::ifstream file(path);
if (!file.is_open())
{
Logger::FILESYS->error("Could not open file: {}", path);
return false;
}
std::string line;
while (std::getline(file, line))
{
if (line.find(searchString) != std::string::npos)
{
return true;
}
}
return false;
}
}

View File

@@ -61,5 +61,7 @@ namespace OpenVulkano
[[maybe_unused]] [[nodiscard]] static std::vector<std::filesystem::path> FilesWithExtension(const std::filesystem::path& dir, std::string ext);
[[nodiscard]] static std::string EnsureExtension(const std::string& filename, const std::string_view& extension);
[[nodiscard]] static bool FileContains(const std::filesystem::path& path, const std::string_view& searchString);
};
}