海角望天涯

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>

namespace  fs  =  boost::filesystem;

template<class Fun>
void  traverse(const std::string &path, Fun fun)
{
    fs::path dir(path);
    if (fs::exists(dir))
    {
        fs::directory_iterator item_begin(dir);
        fs::directory_iterator item_end;
        for ( ;item_begin   !=  item_end; item_begin ++ )
        {
            std::string str = (*item_begin).path().string();
            if (fs::is_directory( *item_begin))
            {
                fun(str);
                traverse( str, fun );
            } 
            else 
            {
                fun(str);
            } 
        } 
    }
}


using namespace MSE::CBIR;
int main()
{

    traverse("F:\\img\\", [](const std::string& str)
    {
        std::cout << str << std::endl;
    });
}
posted on 2012-09-12 10:35  海角望天涯  阅读(348)  评论(0编辑  收藏  举报