This repository was archived by the owner on Sep 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirUtils.h
More file actions
69 lines (57 loc) · 1.32 KB
/
DirUtils.h
File metadata and controls
69 lines (57 loc) · 1.32 KB
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
61
62
63
64
65
66
67
68
69
#ifndef __DIR_UTILS__
#define __DIR_UTILS__
#include <vector>
#include <string>
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef __unix__
#define createDir(PTH) mkdir(PTH, 0755)
#else
#include "windows.h"
#define createDir(PTH) CreateDirectory(PTH, NULL)
#endif
using namespace std;
bool dirExists(string path) {
struct stat info;
if(stat(path.c_str(), &info) != 0)
return false;
return bool(info.st_mode & S_IFDIR);
}
inline bool isDir(string path) {
//Lazy wrap for code's beauty sake...
return dirExists(path);
}
void getDirectoriesList(vector<string>& searchIn) {
vector<string> found;
for(string path : searchIn) {
if(isDir(path)) {
DIR* dir = opendir(path.c_str());
dirent* dp = readdir(dir);
do {
string name = dp->d_name;
if(name != "." and name != "..")
if(isDir(path + "/" + name)) {
found.push_back(path + "/" + name);
}
//--
dp = readdir(dir);
} while(dp not_eq NULL);
closedir(dir);
}
}
if(found.size() == 0)
return;
getDirectoriesList(found);
searchIn.insert(searchIn.end(), found.begin(), found.end());
}
void createDirectoryTree(string where, vector<string>& dirsList) {
if(!isDir(where)) {
createDir(where.c_str());
}
for(string path : dirsList) {
createDir((where + "/" + path).c_str());
}
}
#endif