-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot.cpp
48 lines (37 loc) · 949 Bytes
/
snapshot.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
/******************************
Created By: Aishwary Dewangan
Course: M. Tech. CSIS
Roll No.: 2018202016
GitLab Handle: aish_2018202016
******************************/
#include "include/snapshot.h"
vector<string> snapshotBuffer;
void snapshot(const char *dir) {
DIR *dp;
struct dirent *entry;
struct stat statbuf;
if((dp = opendir(dir)) == NULL) {
printStatus("Error: Unable to open directory.");
return;
}
chdir(dir);
string df("\n\n"), de(":\n"), fe("\t");
while((entry = readdir(dp)) != NULL) {
lstat(entry->d_name,&statbuf);
if(S_ISDIR(statbuf.st_mode)) {
if(strcmp(".",entry->d_name) == 0 || strcmp("..",entry->d_name) == 0)
continue;
snapshotBuffer.push_back(df + entry->d_name + de);
snapshot(entry->d_name);
}
else {
snapshotBuffer.push_back(entry->d_name + fe);
}
}
chdir("..");
closedir(dp);
}
vector<string> getSnapshot(const char *dir) {
snapshot(dir);
return snapshotBuffer;
}