Added a function to delete directories.

This commit is contained in:
Leon Styhre 2021-01-31 19:55:57 +01:00
parent 7ab7dcc7c6
commit c63fc39e8d
2 changed files with 21 additions and 1 deletions

View file

@ -676,6 +676,25 @@ namespace Utils
#endif
}
bool removeDirectory(const std::string& path)
{
if (getDirContent(path).size() != 0) {
LOG(LogError) << "Couldn't delete directory as it's not empty";
LOG(LogError) << path;
return false;
}
#if defined(_WIN64)
if (_wrmdir(Utils::String::stringToWideString(path).c_str()) == 0) {
#else
if (rmdir(path.c_str()) != 0) {
#endif
LOG(LogError) << "Couldn't delete directory, permission problems?";
LOG(LogError) << path;
return false;
}
return true;
}
bool createDirectory(const std::string& _path)
{
std::string path = getGenericPath(_path);

View file

@ -53,6 +53,7 @@ namespace Utils
bool renameFile(const std::string& _source_path,
const std::string& _destination_path, bool _overwrite);
bool removeFile(const std::string& _path);
bool removeDirectory(const std::string& path);
bool createDirectory(const std::string& _path);
bool exists(const std::string& _path);