-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
57 lines (42 loc) · 1.02 KB
/
utils.cpp
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
#include "cgss.hpp"
using namespace std;
#if defined(WIN32) || defined(_WIN32)
void MakeDirectories(const string &s) {
CreateDirectory(s.c_str(), nullptr);
}
#else
void MakeDirectories(const string &s) {
char str[512] = {0};
strncpy(str, s.c_str(), 512);
auto len = strlen(str);
for (auto i = 0; i < len; i++) {
if (str[i] == '/') {
str[i] = '\0';
if (access(str, 0) != 0) {
mkdir(str, 0777);
}
str[i] = '/';
}
}
if (len > 0 && access(str, 0) != 0) {
mkdir(str, 0777);
}
}
#endif
string GetFilePath(const string &s) {
const char *filePath = s.c_str();
char *realPath;
realPath = realpath(filePath, NULL);
const auto pos = string(realPath).rfind("/");
if(pos == string::npos){
return realPath;
}
string path = string(realPath).substr(0, pos + 1);
return path;
}
string GetFileName(const string &s) {
const auto dpos = s.rfind("/") + 1;
const auto pos = s.rfind(".");
string filename = s.substr(dpos, pos - dpos);
return filename;
}