Commit 155cddc1 authored by aligungr's avatar aligungr

IO utils improvement

parent 735cd3b1
......@@ -8,6 +8,7 @@
#include "io.hpp"
#include <filesystem>
#include <fstream>
#include <ostream>
......@@ -23,4 +24,21 @@ std::string ReadAllText(const std::string &file)
return content;
}
void CreateDirectory(const std::string &path)
{
if (!std::filesystem::exists(path))
{
if (!std::filesystem::is_directory(path))
throw std::runtime_error("Required path '" + path + "' exists but not a directory.");
std::filesystem::create_directory(path);
std::filesystem::permissions(path, std::filesystem::perms::all);
}
}
bool Exists(const std::string &path)
{
return std::filesystem::exists(path);
}
} // namespace io
......@@ -11,6 +11,10 @@
namespace io
{
void CreateDirectory(const std::string &path);
std::string ReadAllText(const std::string &file);
bool Exists(const std::string &path);
} // namespace io
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment