如何使用boost filesystem獲取給定子文件夾的目錄?how to use boost filesystem to get subfolders?

該方法只可以給出下一級子目錄;輸入爲目錄地址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();

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章