blob: 3ac9906756141a621d75748f99a6a9acd98fb232 (
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
|
#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
namespace LUS {
class PathHelper {
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();
};
};
} // namespace LUS
|