summaryrefslogtreecommitdiff
path: root/ZAPDUtils/Utils/Directory.h
blob: d150f17727cd084982da37de2b07606a330aed7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once

#include <iostream>
#include <string>
#include <vector>

#ifdef USE_BOOST_FS
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#elif __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif

#include "StringHelper.h"

class Directory
{
public:
#ifdef USE_BOOST_FS
	static std::string GetCurrentDirectory()
	{
		return fs::current_path().string();
	}
#else
	static std::string GetCurrentDirectory()
	{
		return fs::current_path().u8string();
	}
#endif

	static bool Exists(const fs::path& path)
	{
		return fs::exists(path);
	}

	static void CreateDirectory(const std::string& path)
	{
		std::string curPath;
		std::vector<std::string> split = StringHelper::Split(path, "/");

		for (std::string s : split)
		{
			curPath += s + "/";

			if (!Exists(curPath))
				fs::create_directory(curPath);
		}

		// fs::create_directory(path);
	}
};