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