【发布时间】:2017-03-03 14:44:03
【问题描述】:
这是boost directory_iterator example - how to list directory files not recursive 的后续问题。
程序
#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";
}
}
列出目录中的文件,不是递归的,但也列出子目录的名称。我只想列出文件而不是子目录。
如何更改代码以实现此目的?
【问题讨论】: