Added a FileSystemUtil function to create an empty file

This commit is contained in:
Leon Styhre 2023-07-31 17:40:06 +02:00
parent 0267a9db00
commit 66555101bf
2 changed files with 35 additions and 0 deletions

View file

@ -733,6 +733,40 @@ namespace Utils
#endif
}
bool createEmptyFile(const std::string& path)
{
if (exists(path)) {
#if defined(_WIN64)
LOG(LogError) << "Couldn't create target file \""
<< Utils::String::replace(path, "/", "\\")
<< "\" as it already exists";
return false;
}
std::ofstream targetFile {Utils::String::stringToWideString(path).c_str(),
std::ios::binary};
if (targetFile.fail()) {
LOG(LogError) << "Couldn't create target file \""
<< Utils::String::replace(path, "/", "\\")
#else
LOG(LogError) << "Couldn't create target file \"" << path
<< "\" as it already exists";
return false;
}
std::ofstream targetFile {path, std::ios::binary};
if (targetFile.fail()) {
LOG(LogError) << "Couldn't create target file \"" << path
#endif
<< "\", permission problems?";
targetFile.close();
return false;
}
targetFile.close();
return true;
}
bool removeFile(const std::string& path)
{
const std::string& genericPath {getGenericPath(path)};

View file

@ -58,6 +58,7 @@ namespace Utils
bool renameFile(const std::string& sourcePath,
const std::string& destinationPath,
bool overwrite);
bool createEmptyFile(const std::string& path);
bool removeFile(const std::string& path);
bool removeDirectory(const std::string& path);
bool createDirectory(const std::string& path);