#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
//定义函数recursion,递归遍历全部文件夹
void recursion(path src_path)
{
fs::directory_iterator end; //迭代器的终点
for (fs::directory_iterator dir(src_path); dir!=end; dir++)
{
//if (dir->path().extension() != ".jpg")
//continue;
string fn = dir->path().string();
//cout << "file path:" << fn << endl;
if (dir->path().extension() == ".jpg") {
outf << "路径包含jpg名字:" << fn << endl;
}
if (fs::is_directory(*dir))
recursion(*dir); //检查路径是否与目录对应(是文件夹则递归)
}
}
//读取单层文件夹
void readfolder(string folderdir) {
DIR * dir;
struct dirent * ptr;
string x,dirPath;
dir = opendir((char *)folderdir.c_str()); //打开一个目录
while((ptr = readdir(dir)) != NULL) //循环读取目录数据
{
x=ptr->d_name;
if (x.length() < 5) {
continue;
}
dirPath = folderdir + "/" + x;
cout << "dirPath:" << dirPath << endl;
}
closedir(dir);//关闭目录指针
}
int main(int argc, char* argv[]) {
//readtxtfile();
//readfolder("./xinshangpic");
recursion("/data/project/xing/xinshang_dataset/xinshang_img/");
}