首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >带过滤器的boost::filesystem::recursive_directory_iterator

带过滤器的boost::filesystem::recursive_directory_iterator
EN

Stack Overflow用户
提问于 2013-08-14 21:51:42
回答 1查看 18.7K关注 0票数 18

我需要递归地从目录和它的子目录中获取所有文件,但不包括几个目录。我知道他们的名字。有没有可能使用boost::filesystem::recursive_directory_iterator?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-14 22:01:16

是的,在迭代目录时,您可以测试排除列表中的名称,并使用递归迭代器的no_push()成员来防止它进入这样的目录,如下所示:

代码语言:javascript
代码运行次数:0
运行
复制
void selective_search( const path &search_here, const std::string &exclude_this_directory)
{
    using namespace boost::filesystem;
    recursive_directory_iterator dir( search_here), end;
    while (dir != end)
    {
        // make sure we don't recurse into certain directories
        // note: maybe check for is_directory() here as well...
        if (dir->path().filename() == exclude_this_directory)
        {
            dir.no_push(); // don't recurse into this directory.
        }

        // do other stuff here.            

        ++dir;
    }
 }
票数 25
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18233640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档