boost递归遍历文件夹
来源:互联网 发布:体育产业发展数据 编辑:程序博客网 时间:2024/05/17 01:20
最近一直处于非常忙碌的状态,一直没有时间给大家带来新的boost使用的文章,好不容易抽出20分钟,这里给大家带来了一个文件夹遍历,并且更加一个源文件目录,构建一个与源文件类似的目标目录。
废话少说,先贴上代码:
#include <boost/filesystem.hpp>#include <string>void resucurePath(boost::filesystem::path src_path, boost::filesystem::path dest_path){ using namespace boost::filesystem; if (is_directory(src_path)) { directory_iterator tmp_directory_end; directory_iterator tmp_dir_it(src_path); for (tmp_dir_it; tmp_dir_it != tmp_directory_end; tmp_dir_it++) { path child_dest_path = dest_path; if (is_directory(*tmp_dir_it)) { std::string tmp_dir_name = (*tmp_dir_it).path().filename().string(); child_dest_path.append(tmp_dir_name.begin(), tmp_dir_name.end()); if (!exists(child_dest_path)) { create_directory(child_dest_path); } std::cout << child_dest_path << std::endl; } else { std::string tmp_dir_name = (*tmp_dir_it).path().stem().string(); child_dest_path.append(tmp_dir_name.begin(), tmp_dir_name.end()); } resucurePath((*tmp_dir_it).path(), child_dest_path); } } else if (is_regular_file(src_path)) { FILE *fp(NULL); fp = fopen(dest_path.string().c_str(), "w+b"); fclose(fp); fp = NULL; std::cout << dest_path << std::endl; } }void main(){ using namespace boost::filesystem; path src_path("E:/test/test_dir/test_src"); path dest_path("E:/test/test_dir/test_dest"); resucurePath(src_path, dest_path);}这里的路径是我自己的测试路径,大家可以随意指定自己需要构建的路径。boost里面提供了建立文件夹,路径的拼接,获取文件名,获取不带后缀的文件名。上面的函数都有用到了,大家自己做个测试就一切都懂了!最后来一个图(避免无图无真相):
0 0
- boost递归遍历文件夹
- boost递归遍历文件夹
- 使用boost filesystem递归遍历文件夹
- C++遍历文件夹,使用boost filesystem递归遍历文件夹
- C++遍历文件夹,使用boost filesystem递归遍历文件夹
- C++遍历文件夹,使用boost filesystem递归遍历文件夹
- boost 遍历文件夹
- 使用递归遍历文件夹
- 递归法遍历文件夹
- VBS递归遍历文件夹
- 非递归遍历文件夹
- 非递归遍历文件夹
- 递归遍历文件(文件夹)
- java 递归遍历文件夹
- 非递归遍历文件夹
- 文件夹递归遍历
- php递归遍历文件夹
- 非递归遍历文件夹
- iOS基础(三)常用的相互转换的类
- How To Install and Use Redis
- PHP检验身份证代码
- 计算两个坐标之间距离的函数
- (题号)UVa OJ全部题目列表
- boost递归遍历文件夹
- java基本类库和开发框架
- ORA-01405: 提取的列值为 NULL--报错原因及解决方案
- 数位DP
- 第十周项目一 程序填空
- [NodeJS]Node.js 打造实时多人游戏框架
- 用git 的网址
- U7B0 FkFY8ugg雪靴 OcT9 X8V
- 5Crn XujGIugg w4cD TdE