-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpwd.cpp
More file actions
70 lines (55 loc) · 1.69 KB
/
pwd.cpp
File metadata and controls
70 lines (55 loc) · 1.69 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
70
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
#include "os.h"
using namespace std;
string dirStructure= "";
void getDirectoryStructure(string dir, string prefix, vector<string>& ignore) {
string filepath;
DIR *dp;
struct dirent *dirp;
struct stat filestat;
dp = opendir(dir.c_str());
if (dp == NULL) {
cout << "Error " << errno << " while trying opening" << dir << endl;
return;
}
while (dirp = readdir(dp)) {
#ifdef OS_Windows
filepath = dir + "\\" + dirp->d_name;
#else
filepath = dir + "/" + dirp->d_name;
#endif
string nameString(dirp->d_name);
if(std::find(ignore.begin(), ignore.end(), nameString) != ignore.end() ||
std::find(ignore.begin(), ignore.end(), filepath) != ignore.end()) {
continue;
} else {
string tmpprefix = prefix;
tmpprefix.replace(tmpprefix.size()-3, 3, "├─");
dirStructure += tmpprefix + dirp->d_name + "\n";
}
if (stat(filepath.c_str(), &filestat)) {
continue;
}
if (S_ISDIR(filestat.st_mode)) {
getDirectoryStructure(filepath, prefix + " │", ignore);
}
}
closedir(dp);
}
vector<string> buildIgnoreVector() {
vector<string> ignore;
/* Ignore the following file and folder names */
ignore.push_back(".");
ignore.push_back("..");
ignore.push_back("node_modules");
ignore.push_back("bower_components");
ignore.push_back(".git");
ignore.push_back(".vscode");
return ignore;
}