#include <iostream> #include <fstream> #include <string> #include <vector> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dirent.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> using namespace std; #define dmax(a,b) (((a) > (b)) ? (a) : (b)) #define dmin(a,b) (((a) < (b)) ? (a) : (b)) //获取特定格式的文件名 int readFileList(std::vector<string> &filelist, const char *basePath, string format) { DIR *dir; struct dirent *ptr; char base[1000]; if ((dir=opendir(basePath)) == NULL) { perror("Open dir error..."); exit(1); } while ((ptr=readdir(dir)) != NULL) { if(strcmp(ptr->d_name,".")==0 || strcmp(ptr->d_name,"..")==0) ///current dir OR parrent dir continue; else if(ptr->d_type == 8) //file { //printf("d_name:%s/%s ",basePath,ptr->d_name); string temp = ptr->d_name; //cout << temp << endl; string sub = temp.substr(temp.length() - 4, temp.length()-1); //cout << sub << endl; if(sub == format) { string path = basePath; path += "/"; path += ptr->d_name; filelist.push_back(path); } } else if(ptr->d_type == 10) ///link file { //printf("d_name:%s/%s ",basePath,ptr->d_name); } else if(ptr->d_type == 4) ///dir { memset(base,'