该方法只可以给出下一级子目录;输入为目录地址string, 给出放在子文件夹的vector中,并且输出子文件的个数;
参考文献:http://blog.csdn.net/tujiaw
源码:
#include <boost/filesystem.hpp>
#include <iostream>
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();
}