To the recursion part, i got a segmentation fault. Can some one help me out?
Code:
int main(argc,argv)
int argc;
char **argv;
{
DIR *dhandle;
struct dirent *entry3;
unsigned char done = 0;
char path[255];
if (argc !=2) sprintf(path,".");
else strcpy(path,argv[1]);
dhandle=opendir(path);
for (entry3=readdir(dhandle);entry3!=NULL;entry3=readdir(dhandle))
printfDetails(entry3->d_name);
rewinddir(dhandle);
recursive(dhandle);
closedir(dhandle);
}
recursive(d)
DIR *d; {
int exists;
struct stat statbuf;
struct dirent *entry;
for (entry=readdir(d);entry!=NULL;)
{
exists=stat(entry->d_name,&statbuf);
if ((exists>=0)&&(S_ISREG(statbuf.st_mode)))
printf("%20s\n",entry->d_name);
else if ((exists>=0)&&(S_ISDIR(statbuf.st_mode))&&(entry->d_name[0]!='.')
)
{
d=opendir(entry->d_name);
recursive (d);
}
else /* bypass the hidden files and . and .. */;
}
}