Hi Everyone:
This problem is puzzling me if I use this code which includes getwd:
Code:
while (1) {
dirslot=readdir(dir);
if (dirslot==NULL) return;
if (strcmp(dirslot->d_name, ".")==0) ||(strcmp(dirslot->d_name, "..")==0) continue;
stat(dirslot->d_name, &statbuff);
if (S_ISDIR(statbuff.st_mode)) {
if (getwd(pathname) == NULL )
{ printf("Error getting path\n");
exit(0);
}
printf("\n\n %s\n",pathname);
printf("______________________________________\n");
if (chdir(dirslot->d_name)==-1) {
perror("FAIL: Change Directory");
return;}
recls(".");
chdir("..");
}
}
closedir(dir);
}
It will display the full filepath of directories and directories within directories but not the next level down e.g dir----dir-----dir(no display), if you understand what I mean. But if I use this code:
Code:
while (1) {
dirslot=readdir(dir);
if (dirslot==NULL) return;
if (strcmp(dirslot->d_name, ".")==0) ||(strcmp(dirslot->d_name, "..")==0) continue;
stat(dirslot->d_name, &statbuff);
if (S_ISDIR(statbuff.st_mode)) {
printf("\n\n %s\n",dirslot_d_name)
printf("______________________________________\n");
if (chdir(dirslot->d_name)==-1) {
perror("FAIL: Change Directory");
return;}
recls(".");
chdir("..");
}
}
closedir(dir);
}
It will print out the full directory structure but only the directory names which is not what I want.
My Question is, can anybody suggest where Im going wrong with the getcw directory code and how can I fix it so that it will display all directory paths
Please dont flame my code, I know theres not to many error catchment statements but I am fairly new to this C coding.
Thanks for any help.
Christian