2021-01-02 04:24:29 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <iostream>
|
2021-03-20 16:02:12 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2021-01-02 04:24:29 +00:00
|
|
|
|
2023-10-25 01:36:10 +00:00
|
|
|
#ifdef USE_BOOST_FS
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
#elif __has_include(<filesystem>)
|
2021-01-02 04:24:29 +00:00
|
|
|
#include <filesystem>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
#else
|
|
|
|
#include <experimental/filesystem>
|
|
|
|
namespace fs = std::experimental::filesystem;
|
|
|
|
#endif
|
|
|
|
|
2021-03-20 16:02:12 +00:00
|
|
|
#include "StringHelper.h"
|
|
|
|
|
2021-01-02 04:24:29 +00:00
|
|
|
class Directory
|
|
|
|
{
|
|
|
|
public:
|
2023-10-25 01:36:10 +00:00
|
|
|
#ifdef USE_BOOST_FS
|
|
|
|
static std::string GetCurrentDirectory()
|
|
|
|
{
|
|
|
|
return fs::current_path().string();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static std::string GetCurrentDirectory()
|
|
|
|
{
|
|
|
|
return fs::current_path().u8string();
|
|
|
|
}
|
|
|
|
#endif
|
2021-01-02 04:24:29 +00:00
|
|
|
|
2023-10-25 01:36:10 +00:00
|
|
|
static bool Exists(const fs::path& path)
|
|
|
|
{
|
|
|
|
return fs::exists(path);
|
|
|
|
}
|
2021-01-02 04:24:29 +00:00
|
|
|
|
2021-01-09 00:38:28 +00:00
|
|
|
static void CreateDirectory(const std::string& path)
|
2021-01-02 04:24:29 +00:00
|
|
|
{
|
2021-10-17 11:32:09 +00:00
|
|
|
std::string curPath;
|
2021-01-25 00:36:40 +00:00
|
|
|
std::vector<std::string> split = StringHelper::Split(path, "/");
|
|
|
|
|
|
|
|
for (std::string s : split)
|
|
|
|
{
|
|
|
|
curPath += s + "/";
|
|
|
|
|
|
|
|
if (!Exists(curPath))
|
|
|
|
fs::create_directory(curPath);
|
|
|
|
}
|
|
|
|
|
2021-03-20 16:02:12 +00:00
|
|
|
// fs::create_directory(path);
|
2021-01-02 04:24:29 +00:00
|
|
|
}
|
2021-01-09 00:38:28 +00:00
|
|
|
};
|