tut6b.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // filesystem tut6b.cpp --------------------------------------------------------------//
  2. // Copyright Beman Dawes 2010
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. // Library home page: http://www.boost.org/libs/filesystem
  6. #include <iostream>
  7. #include <exception>
  8. #include <boost/filesystem.hpp>
  9. using namespace boost::filesystem;
  10. int main(int argc, char* argv[])
  11. {
  12. if (argc < 2)
  13. {
  14. std::cout << "Usage: tut6b path\n";
  15. return 1;
  16. }
  17. try
  18. {
  19. for (recursive_directory_iterator it (argv[1]);
  20. it != recursive_directory_iterator();
  21. )
  22. {
  23. for (int i = 0; i <= it.level(); ++i)
  24. std::cout << " ";
  25. std::cout << it->path() << '\n';
  26. try { ++it; }
  27. catch (const filesystem_error& ex)
  28. {
  29. std::cout << "************* filesystem_error *****************\n";
  30. std::cout << ex.what() << '\n';
  31. }
  32. }
  33. }
  34. catch (const std::exception& ex)
  35. {
  36. std::cout << "************* exception *****************\n";
  37. std::cout << ex.what() << '\n';
  38. }
  39. return 0;
  40. }