我有这个功能
void file_listing(){
DIR *dp;
struct stat fileStat;
struct dirent *ep;
int file=0;
dp = opendir ("./");
if (dp != NULL){
while ((ep = readdir(dp))){
char *c = ep->d_name;
char d = *c; /* first char */
if((file=open(ep->d_name,O_RDONLY)) < -1){
perror("Errore apertura file");
}
if(fstat(file,&fileStat)){ /*file info */
perror("Errore funzione fstat");
}
if(S_ISDIR(fileStat.st_mode)){ /* directory NOT listed */
continue;
}
else{
if(d != '.'){ /* if filename DOESN'T start with . will be listed */
"save into someting" (ep->d_name);
}
else{
continue; /* altrimenti non lo listo */
}
}
}
(void) closedir (dp);
}
else{
perror ("Impossibile aprire la directory");
return 1;
}
}
我想将文件列表的结果保存到数组或结构或列表或其他东西中,但我不知道该怎么做。
提前致谢!