|
这是段函数的作用是扫描文件夹和子文件夹里的mp3,wma,flac文件,并打印在屏幕上,但总是出错。
每次段错误都出在“dir_ent=readdir(dir);”,我试过把出错目录里的文件删除了几个,但是程序扫描了一回后又出错了。
void openfile(char *filename_)
{
char filename[128];
DIR *dir;
struct dirent *dir_ent;
dir=opendir(filename_);
while(TRUE)
{
dir_ent=readdir(dir);
if(dir_ent==NULL)break;
if(!strcmp(dir_ent->d_name,"..")||!strcmp(dir_ent->d_name,"."))continue;
strcpy(filename,filename_);
strcat(filename,"/");
strcat(filename,dir_ent->d_name);
struct stat buf;
stat(filename,&buf);
if(S_ISDIR(buf.st_mode))openfile(filename);
else
if(
!strcmp(filename+strlen(filename)-4,".mp3")||
!strcmp(filename+strlen(filename)-4,".wma")||
!strcmp(filename+strlen(filename)-5,".flac")
)
printf("%s\n",filename);
};
} |
|