summaryrefslogtreecommitdiff
path: root/ZAPD/Utils/Path.h
blob: 0f7ef2743104ffa111696ed99e2502e8cc736552 (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
#pragma once

#include <iostream>
#include <string>
#include "Utils/StringHelper.h"

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

class Path
{
public:
	static std::string GetFileName(const fs::path& input)
	{
		// https://en.cppreference.com/w/cpp/filesystem/path/filename
		return input.filename().string();
	};

	static std::string GetFileNameWithoutExtension(const fs::path& input)
	{
		// https://en.cppreference.com/w/cpp/filesystem/path/stem
		return input.stem().string();
	};

	static std::string GetFileNameExtension(const std::string& input)
	{
		return input.substr(input.find_last_of("."), input.length());
	};

	static fs::path GetPath(const std::string& input)
	{
		std::vector<std::string> split = StringHelper::Split(input, "/");
		fs::path output;

		for (std::string str : split)
		{
			if (str.find_last_of(".") == std::string::npos)
				output /= str;
		}

		return output;
	};

	static fs::path GetDirectoryName(const fs::path& path) { return path.parent_path(); };
};