3
// Created by: adrian <adrian@lisas.de>
4
// Created on: Thu Jan 30 17:28:51 2003
13
directory::directory(string current_dir)
15
struct stat stat_struct;
16
struct dirent *dirent_struct;
22
current_dir = normalize_path(current_dir);
24
if ((current_dir.find("/dev/")==0) || (current_dir.find("/proc/")==0))
27
stop = current_dir.rfind("/") - 1;
28
start = current_dir.rfind("/",stop);
29
short_name = current_dir.substr(start+1,stop-start);
31
this->current_dir = current_dir;
32
/* does the directory exist */
33
if (stat(current_dir.c_str(), &stat_struct) == -1)
35
dir = opendir(current_dir.c_str());
38
dirent_struct = readdir(dir);
39
while (dirent_struct) {
40
full_path = current_dir;
41
full_path += dirent_struct->d_name;
42
if (is_dir(full_path) && !(!strcmp(dirent_struct->d_name, ".")))
43
directories.push_back(dirent_struct->d_name);
44
if (!is_dir(full_path))
45
files.push_back(dirent_struct->d_name);
46
dirent_struct = readdir(dir);
52
bool directory::is_dir(string dir)
54
struct stat stat_struct;
56
stat(dir.c_str(), &stat_struct);
57
if (stat_struct.st_mode & S_IFDIR)
62
directory::~directory()
64
printf("deleted: %s\n",current_dir.c_str());
67
bool directory::has_childs()
74
int directory::how_many()
76
return (int) directories.size();
79
int directory::how_many_files()
81
return (int) files.size();
84
int directory::how_many_childs()
86
return (int) childs.size();
89
string directory::get_directory(int id) {
90
if (id < 0 || id >= how_many())
92
list <string> :: iterator dir;
94
for (dir = directories.begin(); dir != directories.end(); dir++) {
101
string directory::get_file(int id) {
102
if (id < 0 || id >= how_many_files())
104
list <string> :: iterator file;
106
for (file = files.begin(); file != files.end(); file++) {
113
directory* directory::get_childs(int id) {
114
if (id < 0 || id >= how_many_childs())
116
list <directory *> :: iterator dir;
118
for (dir = childs.begin(); dir != childs.end(); dir++) {
125
string directory::get_current()
130
string directory::get_short_name() {
134
void directory::make_childs()
137
list <string> :: iterator dir;
138
for (dir = directories.begin(); dir != directories.end(); dir++) {
139
childs.push_back(new directory(current_dir + *dir));
143
string directory::normalize_path(string path) {
144
if (path.substr(path.size()-1,path.size()).compare("/"))
150
directory *directory::get_child_by_path(string path) {
151
path = normalize_path(path);
152
list <directory *> :: iterator dir;
153
for (dir = childs.begin(); dir != childs.end(); dir++) {
154
printf("%s:%s:%d\n",(*dir)->get_current().c_str(),
155
path.c_str(),path.size());
156
if (!(*dir)->get_current().compare(0,path.size(),path))