-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSTreeTraversal.cpp
More file actions
56 lines (45 loc) · 1.15 KB
/
FSTreeTraversal.cpp
File metadata and controls
56 lines (45 loc) · 1.15 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
/*
*/
#include "FSTree.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
void filePath(DirNode *dir, vector<DirNode*> &path);
string tracker(stringstream ss, DirNode *directory);
int main (int argc, char *argv[]) {
if (argc != 2) {
cout << "not enough files entered" << endl;
return 0;
}
string directoryName = argv[1];
FSTree directory(directoryName);
vector<DirNode*> path;
filePath(directory.getRoot(), path);
return 0;
}
void filePath(DirNode *dir, vector<DirNode*> &path) {
if (dir == nullptr) {
return;
}
else {
path.push_back(dir);
}
if (dir->hasSubDir()) {
for (int i = 0; i < dir->numSubDirs(); i++) {
filePath(dir->getSubDir(i), path);
}
}
if (dir->hasFiles()) {
for (int i = 0; i < dir->numFiles(); i++) {
cout << path[0]->getName();
for (int j = 1; j < int (path.size()); j++) {
cout << "/" << path[j]->getName();
}
cout << "/" << dir->getFile(i) << endl;
}
}
path.pop_back();
}