walkthrough.cc 631 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <string>
  2. #include <boost/filesystem/path.hpp>
  3. #include <boost/filesystem/operations.hpp>
  4. #include "walkthrough.hh"
  5. using namespace boost::filesystem;
  6. bool walkthrough(path a_path, void (*f_cb)(void *, path), void *a_data)
  7. {
  8. bool result = false;
  9. if(exists(a_path) && is_directory(a_path))
  10. {
  11. directory_iterator it_end;
  12. for(directory_iterator it(a_path); it != it_end; ++it)
  13. {
  14. if(is_directory(it->status()))
  15. {
  16. walkthrough(it->path().string(), f_cb, a_data);
  17. }
  18. else if(is_regular_file(it->status()))
  19. {
  20. f_cb(a_data, it->path().string());
  21. }
  22. }
  23. result = true;
  24. }
  25. return result;
  26. }