清单目录中的boost ::文件系统的文件递归 [英] list directory files recursively with boost::filesystem

查看:316
本文介绍了清单目录中的boost ::文件系统的文件递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用新的动力,V1.5.3,开展这项工作就像下,由于类recursive_directory_iterator(我没有写递归code):

I'm using new boost, v1.5.3, to carry out this task like following, thanks to the class recursive_directory_iterator (I don't have to write recursive code):

void ListDirRec(const char *Dir, vector<string>& DirFileList, const char* ext)
{    
recursive_directory_iterator rdi(Dir);  
recursive_directory_iterator end_rdi;

DirFileList.empty();

string ext_str0(ext);   
for (; rdi != end_rdi; rdi++)
{
    rdi++;
    //cout << (*di).path().string() << endl;
    cout << (*rdi).path().string() << endl;

    //cout << " <----- " << (*rdi).path().extension() << endl;

    //string ext_str1 = (*rdi).path().extension().string();
    if (ext_str0.compare((*rdi).path().extension().string()) == 0)
    {
        DirFileList.push_back((*rdi).path().string());
    }
}

函数列表文件与特定扩展。此功能为案件,但经常返回断言失败错误,如:

the function list files with specific extension. This function works for cases but frequently return an "assertion fails error" like:

**** Internal program error - .... assertion (m_imp.get()) ... operations.hpp(952): dereference of end recursive_directory_iterator

我刚刚想出这个错误的原因。可以在任何尝试..赶上帮助?
在此先感谢您的帮助。

I barely figure out the cause of this error. Can any try.. catch help? thanks in advance for any help

推荐答案

正在递增 RDI 内循环,以及在声明:

You are incrementing rdi inside the loop as well as in the for declaration:

for (; rdi != end_rdi; rdi++)
{
    rdi++;

这意味着 RDI 可能是 end_rdi (结束迭代器,这意味着过去的最后一个元素)内你的循环。有你这样做的原因是什么? (如果这是故意的,你应该检查,以确保 RDI!= end_rdi 您增加后再次它。)

That means that rdi might be end_rdi (the end-iterator, which means past the last element) within your loop. Is there any reason you're doing this? (If this is intentional, you should check to make sure rdi != end_rdi again after you increment it.)

这篇关于清单目录中的boost ::文件系统的文件递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆