typedef struct file{/*This is the struct to add*/
char* fileNames;
}File;
File* scanDir(char *path,File file[],int i){/*Func works recursively*/
DIR *dir;
struct dirent *dp;
char * file_name;
dir = opendir(path);
if(dir==NULL)
return file;
chdir(path);
while ((dp=readdir(dir)) != NULL) {
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")){}
else {
file_name = dp->d_name; /*use it*/
printf("file_name: \"%s\"\n",file_name);
file[i]=create(file_name,file[i]);/*This create function adds the file name into the file struct*/
i++;
scanDir(dp->d_name,file,i);
}
}
chdir("..");
closedir(dir);
return file;
}
我正在尝试向struct array添加文件名。 int我计算数组顺序。 如何通过添加到struct array来读取文件?