Go to the documentation of this file. 1 #ifndef CONSCIENCE_UTIL_FS_h
2 #define CONSCIENCE_UTIL_FS_h
7 namespace fs = std::filesystem;
24 optional<unsigned>
findLineInFile(
const string &searchedString,
const string &path,
string *lineContent =
nullptr);
30 void writeBytesToFile(
const string &outPath,
const vector<unsigned char> &content);
36 void collectPathsRecursively(
const fs::path &fromDirectory, vector<fs::path> &collectedPaths,
const vector<string> &allowedExtensions = {});
44 inline bool hasExtension(
const fs::path &filePath,
const string &extension) {
45 return filePath.extension().string() == extension || filePath.extension().string() == string(
"." + extension);
48 inline bool hasAnyExtension(
const fs::path &filePath,
const vector<string> &extensions) {
49 for (
const string &extension : extensions) {
57 optional<bool>
replaceLineInFile(
const std::string &filePath,
const std::string &searchedToken,
const std::string &replacement);
string readFileToString(const string &path)
Definition: fs.cpp:28
optional< bool > replaceLineInFile(const std::string &filePath, const std::string &searchedToken, const std::string &replacement)
Definition: fs.cpp:148
void writeBytesToFile(const string &outPath, const vector< unsigned char > &content)
Definition: fs.cpp:101
vector< unsigned char > * readFileToBytes(const string &path)
Definition: fs.cpp:85
fs::path resolvePathFromEnvironment(const char *envVar, const string ¯o, std::optional< fs::path > defaultPath)
Definition: fs.cpp:11
bool hasExtension(const fs::path &filePath, const string &extension)
Definition: fs.h:44
void writeStringToFile(const string &outPath, const string &content)
Definition: fs.cpp:92
bool isParentDirectory(const fs::path &filePath, const fs::path &directoryPath)
Definition: fs.cpp:139
optional< unsigned > findLineInFile(const string &searchedString, const string &path, string *lineContent)
Definition: fs.cpp:61
bool hasAnyExtension(const fs::path &filePath, const vector< string > &extensions)
Definition: fs.h:48
bool isFileModifiedRecently(const fs::path &filePath, unsigned long long durationMillis)
Definition: fs.cpp:120
bool canReadFile(const fs::path &filePath)
Definition: fs.cpp:49
void collectPathsRecursively(const fs::path &fromDirectory, vector< fs::path > &collectedPaths, const vector< string > &allowedExtensions)
Definition: fs.cpp:107