如何使用boost filesystem获取给定子文件夹的目录?how to use boost filesystem to get subfolders?

该方法只可以给出下一级子目录;输入为目录地址string, 给出放在子文件夹的vector中,并且输出子文件的个数;
参考文献:http://blog.csdn.net/tujiaw
源码:

#include   
#include 
namespace fs = boost::filesystem;

int get_subfolders(const std::string& dir, std::vector<std::string>& filenames)
{
    fs::path path(dir);
    if (!fs::exists(path))
    {
        return -1;
    }
    fs::directory_iterator end_iter;
    for (fs::directory_iterator iter(path); iter != end_iter;++iter)
    {
        if (fs::is_directory(iter->status()))
        {
            filenames.push_back(iter->path().string());
        }
    }
    return filenames.size();

}

你可能感兴趣的:(C++,boost,c++)