aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-09-16 16:34:45 +0200
committerMartin Ridgers <[email protected]>2021-09-16 16:34:45 +0200
commit789a34d63b8626e6b35b456ce2edd5a274f66aff (patch)
tree7b7be1bdc6ffdba087c3ffe5177bb1be6bdcadd2 /zencore/filesystem.cpp
parentThe wchar_t variants of directory functions are now only enabled on Windows (diff)
downloadzen-789a34d63b8626e6b35b456ce2edd5a274f66aff.tar.xz
zen-789a34d63b8626e6b35b456ce2edd5a274f66aff.zip
Non-Windows implementation of Clean/DeleteDirectory() using std::fs
Diffstat (limited to 'zencore/filesystem.cpp')
-rw-r--r--zencore/filesystem.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 1ddde9d88..fb22befdf 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -169,13 +169,35 @@ CreateDirectories(const std::filesystem::path& Dir)
bool
DeleteDirectories(const std::filesystem::path& Dir)
{
+#if ZEN_PLATFORM_WINDOWS
return DeleteDirectories(Dir.c_str());
+#else
+ std::error_code ErrorCode;
+ return std::filesystem::remove_all(Dir, ErrorCode);
+#endif
}
bool
CleanDirectory(const std::filesystem::path& Dir)
{
+#if ZEN_PLATFORM_WINDOWS
return CleanDirectory(Dir.c_str());
+#else
+ if (std::filesystem::exists(Dir))
+ {
+ bool Success = true;
+
+ std::error_code ErrorCode;
+ for (const auto& Item : std::filesystem::directory_iterator(Dir))
+ {
+ Success &= std::filesystem::remove_all(Item, ErrorCode);
+ }
+
+ return Success;
+ }
+
+ return CreateDirectories(Dir);
+#endif
}
//////////////////////////////////////////////////////////////////////////