-
Notifications
You must be signed in to change notification settings - Fork 5
/
dirtreetest.cpp
91 lines (76 loc) · 1.48 KB
/
dirtreetest.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <dirent.h>
#include <sys/stat.h>
#include "support/dirtreewalker.h"
using namespace std;
int main(int argc,char **argv)
{
try
{
if(argc>1)
{
DirTreeWalker toplevel(argv[1]);
DirTreeWalker *dir=toplevel.NextDirectory();
while(dir)
{
vector<string> strlist;
const char *file;
while((file=dir->NextFile()))
strlist.push_back(string(file));
sort(strlist.begin(),strlist.end());
vector<string>::const_iterator it;
for(it=strlist.begin(); it!=strlist.end(); ++it)
cerr << "File: " << *it << endl;
dir=dir->NextDirectory();
}
cerr << endl << " ----- High level - files ----- " << endl;
DirTree_Files dtf(argv[1]);
const char *fn;
while((fn=dtf.Next()))
{
cerr << fn << endl;
}
cerr << endl << " ----- High level - directories ----- " << endl;
DirTree_Dirs dtd(argv[1]);
while((fn=dtd.Next()))
{
cerr << fn << endl;
}
}
}
catch(const char *err)
{
cerr << "Error: " << err << endl;
}
return(0);
}
#if 0
int main(int argc,char **argv)
{
try
{
if(argc>1)
{
DirTreeWalker toplevel(argv[1]);
DirTreeWalker *dir=toplevel.NextDirectory();
while(dir)
{
const char *file;
while((file=dir->NextFile()))
{
cerr << "Got file: " << file << endl;
}
dir=dir->NextDirectory();
}
}
}
catch(const char *err)
{
cerr << "Error: " << err << endl;
}
return(0);
}
#endif