00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 #include "directory.h"
00012
00013 using namespace std;
00014
00015
00016 bool Directory::enumFiles(EnumFilesHandler& handler, bool deep)
00017 {
00018 string filename;
00019
00020 while (nextFile(filename))
00021 {
00022
00023 if (filename[0] == '.')
00024 continue;
00025
00026
00027 string pathname = handler.getPath() + string("/") + filename;
00028 if (IsDirectory(pathname))
00029 {
00030 if (deep)
00031 {
00032 Directory* dir = OpenDirectory(pathname);
00033 bool cont = true;
00034
00035 if (dir != NULL)
00036 {
00037 handler.pushDir(filename);
00038 cont = dir->enumFiles(handler, deep);
00039 handler.popDir();
00040 delete dir;
00041 }
00042
00043 if (!cont)
00044 return false;
00045 }
00046 }
00047 else
00048 {
00049 if (!handler.process(filename))
00050 return false;
00051 }
00052 }
00053
00054 return true;
00055 }
00056
00057
00058 EnumFilesHandler::EnumFilesHandler()
00059 {
00060 }
00061
00062
00063 void EnumFilesHandler::pushDir(const std::string& dirName)
00064 {
00065 if (dirStack.size() > 0)
00066 dirStack.push_back(dirStack.back() + string("/") + dirName);
00067 else
00068 dirStack.push_back(dirName);
00069 }
00070
00071
00072 void EnumFilesHandler::popDir()
00073 {
00074 dirStack.pop_back();
00075 }
00076
00077
00078 const string& EnumFilesHandler::getPath() const
00079 {
00080
00081 static const string emptyString("");
00082
00083 if (dirStack.size() > 0)
00084 return dirStack.back();
00085 else
00086 return emptyString;
00087 }