boost 遍历文件或目录
来源:互联网 发布:淘宝售假扣2分多久清零 编辑:程序博客网 时间:2024/06/13 12:12
#include <iostream>#include <fstream>#include <boost/filesystem.hpp>#include <boost/io/ios_state.hpp>#include <boost/progress.hpp>int main(int argc, char **argv){//////////////////////////////////////////////////////////////////////////// 遍历当前路径下的中的目录,只能迭代本层目录{boost::progress_timer t;{std::ofstream of("path.log");// 保存流的所有状态,以便恢复boost::io::ios_all_saver ifs(std::cout);std::cout.rdbuf(of.rdbuf());boost::filesystem::directory_iterator end;for (boost::filesystem::directory_iterator pos("J:");pos != end;++pos){std::cout << *pos << std::endl;// 返回path类型,继而返回文件名//pos->path().filename();}}}//////////////////////////////////////////////////////////////////////////// 指定深度的目录遍历{boost::progress_timer t;{std::ofstream of("file1.log");// 保存流的所有状态,以便恢复boost::io::ios_all_saver ifs(std::cout);std::cout.rdbuf(of.rdbuf());boost::filesystem::recursive_directory_iterator end;for (boost::filesystem::recursive_directory_iterator pos("J:");pos != end;++pos){if (boost::filesystem::is_directory(*pos) && (pos.level() > 5) ){pos.no_push();}elsestd::cout << "level -- " << pos.level() << ":" << *pos << std::endl;}}}//////////////////////////////////////////////////////////////////////////// 深度迭代所有目录和文件{boost::progress_timer t;{std::ofstream of("file.log");// 保存流的所有状态,以便恢复boost::io::ios_all_saver ifs(std::cout);std::cout.rdbuf(of.rdbuf());boost::filesystem::recursive_directory_iterator end;for (boost::filesystem::recursive_directory_iterator pos("J:");pos != end;++pos){std::cout << "level -- " << pos.level() << ":" << *pos << std::endl;}}}return 0;}
第二个花费的时间过多,是因为每次遍历都执行了三次判断,所以时间稍长。单线程便利只要2秒,相当牛
0 0
- boost 遍历文件或目录
- java遍历目录或文件
- Boost C++ Libraries 遍历文件目录
- boost::filesystem遍历目录
- C/C++遍历目录下的文件或指定文件
- C/C++遍历目录下的文件或指定文件
- java遍历某个目录或文件(树结构展现)
- 遍历递归目录下所有文件或文件夹
- 使用boost中的filesystem类库遍历某个目录所有的文件
- 使用boost中的filesystem类库遍历某个目录所有的文件
- boost::filesystem的文件遍历
- MFC目录遍历与BOOST效率比较
- 使用boost::filesystem实现目录遍历
- ./include/caffe/common.hpp:4:32: fatal error: boost/shared_ptr.hpp: 没有那个文件或目录
- ./include/caffe/common.hpp:4:32: fatal error: boost/shared_ptr.hpp: 没有那个文件或目录
- linux下遍历目录和文件,删除过期天数目录或文件shell脚本
- JSP遍历文件目录
- 遍历文件目录
- 【树的直径】 POJ 1985 Cow Marathon
- 第七周撞错
- 使用 getValueStack() 使数据在JSP页面中回显
- Task和Back Stack(二)
- Accelerated C++:通过示例进行编程实践——练习解答(第5章)
- boost 遍历文件或目录
- FineUIt配置
- 设计模式之---观察者模式
- Codeforces 110A-Nearly Lucky Number(实现)
- J2SE习题(2)
- 写在前面的话
- JQuery实战--可以编辑的表格
- C++ operator关键字(重载操作符)
- 进程与线程的区别联系