如何使用 Boost 和 C++ 递归地单独列出文件和文件夹

How to list files and folders recursively and separately with Boost and C++

在 boost 文档中,我找到了列出目录文件和文件夹的代码(但不是递归 :( ​​),但我不知道如何只生成所有文件的列表,即使是那些文件在子目录中(递归地)或所有文件夹的列表(也是递归地)。

入门指南:

#include <boost/filesystem.hpp>
#include <boost/range/iterator_range.hpp>

namespace fs = boost::filesystem; 

#include <iostream>

int main() {

    for (auto& entry : boost::make_iterator_range(fs::recursive_directory_iterator("."), {}))
    {
        if (fs::is_regular_file(entry))
            std::cout << entry.path() << "\n";
    }

}

打印例如

"./odata/marshal/json_light_test.cpp"
"./odata/marshal/core_test.cpp"
"./odata/marshal/json_verbose_test.cpp"
"./odata/edm/example_test.cpp"
"./odata/edm/builtin_test.cpp"
"./misc/naive_ptr_tests.cpp"
"./json/generic_visitor_tests.cpp"
"./json/json_tests.cpp"
"./azure/storage/test_service_definitions.hpp"
"./azure/storage/blob_tests.cpp"
"./azure/storage/table_tests.cpp"