13 using namespace boost::filesystem;
30 if (thePath.filename().string().find_first_of(
".") == 0 && thePath.filename().string() !=
"." ) {
31 LOG(
ERROR) <<
"DirCrawler::start() : Root cannot be hidden (" << thePath <<
")" << endl;
35 int r = this->
browse(thePath);
46 if (is_regular_file(p)) {
49 }
else if (is_directory(p)) {
54 directory_iterator endItr;
56 for (directory_iterator dItr(p); dItr != endItr; ++dItr) {
58 if (dItr->path().filename().string().find_first_of(
".") == 0)
62 int r =
browse(dItr->path());
69 LOG(
ERROR) <<
"DirCrawler::browse() : This is not a regular File nor a directory : " << p.string() << endl;
72 LOG(
ERROR) <<
"DirCrawler::browse() : The file does not exist : " << p << endl;
76 }
catch (
const filesystem_error& ex) {
77 LOG(
ERROR) <<
"DirCrawler :: " << ex.what() << endl;
int browse(const boost::filesystem::path &p)
applies the required action if file or folder, and browse its children
Fetch a directory and all subdirs.
int start()
Start crawling over all the files and directories/subdirectories.
WsDirectoryCrawler(const std::string &path)
Class constructor, this class is Abstract and must therefore be inherited.
virtual void endChild(const boost::filesystem::path &p)=0
this method is called when finished browsing the subdir
virtual int applyFile(const boost::filesystem::path &p)=0
this method is called by browse when the boost::filesystem::path is a file
virtual void beginChild(const boost::filesystem::path &p)=0
this method is called before browsing a subdirectory
virtual int applyDirectory(const boost::filesystem::path &p)=0
this method is called by browse when the boost::filesystem::path is a folder
virtual ~WsDirectoryCrawler()=0
Virtual destructor.