summaryrefslogtreecommitdiff
path: root/ZAPD/Utils/Directory.h
blob: 8455e52a2532860a8c061170903a4b361c7d5b34 (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
56
57
58
59
60
#pragma once

#include <string>
#include <vector>
#include <ship/utils/StringHelper.h>
#include <iostream>

#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif

#undef GetCurrentDirectory
#undef CreateDirectory

class Directory
{
public:
	#ifndef PATH_HACK
	static std::string GetCurrentDirectory() { return fs::current_path().string(); }
	#endif

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

	// Stupid hack because of Windows.h
	static void MakeDirectory(const std::string& path)
	{
		CreateDirectory(path);
	}

	static void CreateDirectory(const std::string& path)
	{
		try
		{
			fs::create_directories(path);
		}
		catch (...)
		{
		}
	}

	static std::vector<std::string> ListFiles(const std::string& dir)
	{
		std::vector<std::string> lst;

		if (Exists(dir))
		{
			for (auto& p : fs::recursive_directory_iterator(dir))
			{
				if (!p.is_directory())
					lst.push_back(p.path().generic_string());
			}
		}

		return lst;
	}
};