2
Q
遍历目录
A
回答
7
根据你对C++/Boost感兴趣的标签。然后,请从this SO answer借款:
#include <utility>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH
namespace fs = boost::filesystem;
fs::recursive_directory_iterator it(top), eod;
foreach (fs::path const & p, std::make_pair(it, eod)) {
if (is_directory(p)) {
...
} else if (is_regular_file(p)) {
...
} else if (is_symlink(p)) {
...
}
}
另一个版本,从Rosetta code:
#include "boost/filesystem.hpp"
#include "boost/regex.hpp"
#include <iostream>
using namespace boost::filesystem;
int main()
{
path current_dir("."); //
boost::regex pattern("a.*"); // list all files starting with a
for (recursive_directory_iterator iter(current_dir), end;
iter != end;
++iter)
{
std::string name = iter->path().leaf();
if (regex_match(name, pattern))
std::cout << iter->path() << "\n";
}
}
采取
相关问题
- 1. 遍历目录
- 2. 遍历目录树
- 3. R:遍历目录
- 4. Applescript遍历目录
- 5. 目录遍历c
- 6. 遍历两个目录
- 7. 用php遍历目录?
- 8. Ruby中的目录遍历
- 9. 目录遍历问题c#
- 10. 使用Node.js遍历目录
- 11. 遍历目录路径
- 12. 通过http遍历目录
- 13. 目录遍历bash shell
- 14. 递归目录遍历
- 15. Perl子目录遍历
- 16. perl的遍历目录
- 17. 目录遍历攻击
- 18. 用Gulp遍历目录?
- 19. 遍历目录使用Java
- 20. Unix:遍历一个目录
- 21. 笨 - 目录遍历 - sanitize_filename()
- 22. 外壳脚本遍历目录
- 23. 只遍历特定的python目录
- 24. 遍历目录构建菜单结构
- 25. PHP遍历和删除目录问题
- 26. 遍历每天转储目录
- 27. 如何遍历Ant中的目录
- 28. Segfault调用readdir() - 目录遍历
- 29. 遍历Makefile中的目录列表
- 30. 如何遍历目录中的文件?