#include #include #include #include #include void make_file_list(void); char *list_files(char *); int main(void) { make_file_list(); } char * list_files(char *path){ DIR *dir; int subfiles=false; struct dirent *files; dir=opendir(path); char *newpath; char *lastpath; if(dir!=NULL) { while(files = readdir(dir)) if (strcmp(files->d_name,".")!=0 && strcmp(files->d_name,"..")!=0) { subfiles=true; newpath=malloc(sizeof(path)+sizeof(files->d_name)+sizeof(char)); sprintf(newpath,"%s/%s",path,files->d_name); lastpath=list_files(newpath); } closedir(dir); if(!subfiles) { newpath=malloc(sizeof(path)+sizeof(char)); sprintf(newpath,"%s/",path); return newpath; } else return lastpath; } else return path; } void make_file_list(void) { DIR *dp; struct dirent *files; dp = opendir("pkg"); if(dp!=NULL) { while(files = readdir(dp)) if (strcmp(files->d_name,".")!=0 && strcmp(files->d_name,"..")!=0) printf("%s\n",list_files(files->d_name)); closedir(dp); } else perror("Couldn't open the directory"); }