<tfoot id='xOnRX'></tfoot><legend id='xOnRX'><style id='xOnRX'><dir id='xOnRX'><q id='xOnRX'></q></dir></style></legend>
    1. <small id='xOnRX'></small><noframes id='xOnRX'>

          <bdo id='xOnRX'></bdo><ul id='xOnRX'></ul>
      1. <i id='xOnRX'><tr id='xOnRX'><dt id='xOnRX'><q id='xOnRX'><span id='xOnRX'><b id='xOnRX'><form id='xOnRX'><ins id='xOnRX'></ins><ul id='xOnRX'></ul><sub id='xOnRX'></sub></form><legend id='xOnRX'></legend><bdo id='xOnRX'><pre id='xOnRX'><center id='xOnRX'></center></pre></bdo></b><th id='xOnRX'></th></span></q></dt></tr></i><div id='xOnRX'><tfoot id='xOnRX'></tfoot><dl id='xOnRX'><fieldset id='xOnRX'></fieldset></dl></div>
      2. 我可以使用掩码在带有 Boost 的目录中迭代文件吗?

        Can I use a mask to iterate files in a directory with Boost?(我可以使用掩码在带有 Boost 的目录中迭代文件吗?)
            <bdo id='c2Fe6'></bdo><ul id='c2Fe6'></ul>
            <i id='c2Fe6'><tr id='c2Fe6'><dt id='c2Fe6'><q id='c2Fe6'><span id='c2Fe6'><b id='c2Fe6'><form id='c2Fe6'><ins id='c2Fe6'></ins><ul id='c2Fe6'></ul><sub id='c2Fe6'></sub></form><legend id='c2Fe6'></legend><bdo id='c2Fe6'><pre id='c2Fe6'><center id='c2Fe6'></center></pre></bdo></b><th id='c2Fe6'></th></span></q></dt></tr></i><div id='c2Fe6'><tfoot id='c2Fe6'></tfoot><dl id='c2Fe6'><fieldset id='c2Fe6'></fieldset></dl></div>
              <legend id='c2Fe6'><style id='c2Fe6'><dir id='c2Fe6'><q id='c2Fe6'></q></dir></style></legend>

                <tbody id='c2Fe6'></tbody>

              <small id='c2Fe6'></small><noframes id='c2Fe6'>

                <tfoot id='c2Fe6'></tfoot>
                  本文介绍了我可以使用掩码在带有 Boost 的目录中迭代文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想遍历一个目录中匹配somefiles*.txt 之类的所有文件.

                  I want to iterate over all files in a directory matching something like somefiles*.txt.

                  boost::filesystem 是否有内置的东西来做到这一点,或者我是否需要一个正则表达式或针对每个 leaf() 的东西?

                  Does boost::filesystem have something built in to do that, or do I need a regex or something against each leaf()?

                  推荐答案

                  EDIT:如评论中所述,以下代码适用于 boost::filesystem 在 v3 之前.对于 v3,请参考评论中的建议.

                  EDIT: As noted in the comments, the code below is valid for versions of boost::filesystem prior to v3. For v3, refer to the suggestions in the comments.

                  boost::filesystem 没有通配符搜索,你必须自己过滤文件.

                  boost::filesystem does not have wildcard search, you have to filter files yourself.

                  这是一个使用boost::filesystemdirectory_iterator提取目录内容并使用boost::regex过滤的代码示例代码>:

                  This is a code sample extracting the content of a directory with a boost::filesystem's directory_iterator and filtering it with boost::regex:

                  const std::string target_path( "/my/directory/" );
                  const boost::regex my_filter( "somefiles.*.txt" );
                  
                  std::vector< std::string > all_matching_files;
                  
                  boost::filesystem::directory_iterator end_itr; // Default ctor yields past-the-end
                  for( boost::filesystem::directory_iterator i( target_path ); i != end_itr; ++i )
                  {
                      // Skip if not a file
                      if( !boost::filesystem::is_regular_file( i->status() ) ) continue;
                  
                      boost::smatch what;
                  
                      // Skip if no match for V2:
                      if( !boost::regex_match( i->leaf(), what, my_filter ) ) continue;
                      // For V3:
                      //if( !boost::regex_match( i->path().filename().string(), what, my_filter ) ) continue;
                  
                      // File matches, store it
                      all_matching_files.push_back( i->leaf() );
                  }
                  

                  (如果您正在寻找具有内置目录过滤功能的即用型类,请查看 Qt 的 QDir.)

                  (If you are looking for a ready-to-use class with builtin directory filtering, have a look at Qt's QDir.)

                  这篇关于我可以使用掩码在带有 Boost 的目录中迭代文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)
                  <tfoot id='4qiyp'></tfoot>
                1. <small id='4qiyp'></small><noframes id='4qiyp'>

                  <legend id='4qiyp'><style id='4qiyp'><dir id='4qiyp'><q id='4qiyp'></q></dir></style></legend>

                    <tbody id='4qiyp'></tbody>
                      <i id='4qiyp'><tr id='4qiyp'><dt id='4qiyp'><q id='4qiyp'><span id='4qiyp'><b id='4qiyp'><form id='4qiyp'><ins id='4qiyp'></ins><ul id='4qiyp'></ul><sub id='4qiyp'></sub></form><legend id='4qiyp'></legend><bdo id='4qiyp'><pre id='4qiyp'><center id='4qiyp'></center></pre></bdo></b><th id='4qiyp'></th></span></q></dt></tr></i><div id='4qiyp'><tfoot id='4qiyp'></tfoot><dl id='4qiyp'><fieldset id='4qiyp'></fieldset></dl></div>

                        • <bdo id='4qiyp'></bdo><ul id='4qiyp'></ul>