|
unix 可以这么写
int testdir(char *path)
{
struct stat buf;
if(lstat(path,&buf)<0)
{
return 0;
}
if(S_ISDIR(buf.st_mode))
{
return 1; //directory
}
return 0;
}
int directory(char *path,int *p_filenum, char files[][128])
{
DIR *db;
char filename[128];
struct dirent *p;
db=opendir(path);
if(db==NULL)
return -1;
* p_filenum =0;
memset(filename,0,128);
while ((p=readdir(db)))
{
if((strcmp(p->d_name,".")==0)||(strcmp(p->d_name,"..")==0))
continue;
else
{
//sprintf(filename,"%s/%s",path,p->d_name);
sprintf(filename,"%s",p->d_name);
if(testdir(filename))
{
//directory(filename); this function no reg
}
else
{
//if core.* and file return ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4-style, from 'iquery'
if ( strstr(filename,"core.") )
{
printf("%s\n",filename);
if ( *p_filenum < 128 )
{
strcpy( files[*p_filenum ], filename);
*p_filenum=*p_filenum +1 ;
}
}
}
}
memset(filename,0,128);
}
closedir(db);
return 0;
} |
|