If your goal is to learn how to write a recursive function, you might prefer this simple loop based on Boost.Filesystem :
#include "boost/filesystem.hpp" #include <iostream> int main () { for ( boost::filesystem::recursive_directory_iterator end, dir("./"); dir != end; ++dir ) { // std::cout << *dir << "\n"; // full path std::cout << dir->path().filename() << "\n"; // just last bit } }
Or even calling one function:
std::copy( boost::filesystem::recursive_directory_iterator("./"), boost::filesystem::recursive_directory_iterator(), std::ostream_iterator<boost::filesystem::directory_entry>(std::cout, "\n"));
source share