#include <cstdio> #include <cstring> #include <unistd.h> #include<dirent.h> #include <stdlib.h> // Jinxu void get_fileschar *p, char **image_paths, int *img_cnt) { DIR *dir; char base_path[512]; memsetbase_path, 0, sizeof base_path); int offset = 0; ifp && p[0] == '.'){ getcwdbase_path, sizeofbase_path)); // get current work director offset ++; } strcatbase_path, p + offset); struct dirent *ptr; if dir=opendirbase_path)) == NULL) { printf"Open dir: %s Error... ", base_path); exit1); } while ptr=readdirdir)) != NULL) { ifstrcmpptr->d_name,".")==0 || strcmpptr->d_name,"..")==0) ///current dir OR parrent dir continue; ifptr->d_type == 8) ///file .jpg / .png) { //printf"d_name:%s/%s ",base_path,ptr->d_name); /// do strings split joint ifstrcmpptr->d_name + strlenptr->d_name) - 3, "jpg") && strcmpptr->d_name + strlenptr->d_name) - 3, "png")) continue; char *tmp; tmp = char *)mallocstrlenbase_path) + strlenptr -> d_name) + 5) * sizeof char *)); memsettmp, 0, sizeof tmp); sprintftmp, "%s%c%s", base_path, '/', ptr->d_name); image_paths[*img_cnt) ++] = tmp; } } closedirdir); return image_paths; } int main int argc, char** argv ) { char *image_paths[5005]; int img_cnt = 0; get_filesfilename, image_paths, &img_cnt); return 0; }