tut6a.cpp 1008 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // filesystem tut6a.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: tut6a path\n";
  15. return 1;
  16. }
  17. try
  18. {
  19. for (recursive_directory_iterator it (argv[1]);
  20. it != recursive_directory_iterator();
  21. ++it)
  22. {
  23. if (it.level() > 1)
  24. it.pop();
  25. else
  26. {
  27. for (int i = 0; i <= it.level(); ++i)
  28. std::cout << " ";
  29. std::cout << it->path() << '\n';
  30. }
  31. }
  32. }
  33. catch (const std::exception& ex)
  34. {
  35. std::cout << "************* exception *****************\n";
  36. std::cout << ex.what() << '\n';
  37. }
  38. return 0;
  39. }