This is a follow up question to boost directory_iterator example - how to list directory files not recursive.
The program
#include <boost/filesystem.hpp>
#include <boost/range.hpp>
#include <iostream>
using namespace boost::filesystem;
int main(int argc, char *argv[])
{
path const p(argc>1? argv[1] : ".");
auto list = [=] { return boost::make_iterator_range(directory_iterator(p), {}); };
// Save entries of 'list' in the vector of strings 'names'.
std::vector<std::string> names;
for(auto& entry : list())
{
names.push_back(entry.path().string());
}
// Print the entries of the vector of strings 'names'.
for (unsigned int indexNames=0;indexNames<names.size();indexNames++)
{
std::cout<<names[indexNames]<<"\n";
}
}
lists the files in a directory, not recursive, but also lists the names of the subdirectories. I only want to list the files and not the subdirectories.
How do I change the code to achieve this?