I was trying to make an interactive directory menu.
But in the directory where he has to read, there are a few directories that i don't want my menu to show and the "." and ".." still shows to...
I just changed all my specific names so you can modify it easier...
please help me, and here is my code..
at the end there was a switch for the choice list and list_var[n] was a variable that takes the the name of the dir chosen, for further use...Code:#include <stdio.h> #include <errno.h> #include <sys/types.h> #include <dirent.h> #define dir getenv("HOME") main() { DIR *dip; struct dirent *dit; int i = 1; int n = 0; char list_dir[20]; char* list_var[8]; dip = opendir(dir); if (dip == NULL) { perror("opendir"); return(CODE); } while (( dit = readdir(dip)) != NULL) { start: sprintf(list_dir,"%s",dit->d_name); if (list_dir = "bad_dir"){goto start;} if(list_dir == "."){goto start;} if(list_dir == ".."){goto start;} printf("\t\t\t(%d) %s\n",i,list_dir); list_var[n] = list_dir; i++; n++; } if (closedir(dip) == -1) { perror("closedir"); return 0; } }
But the problem here...
1 -> it still doesn't exclude the "." ".." and "bad_dir" from my list
2 -> my list_var always give the last dir in my case always the ".." :-(
Please give me some help i've changed this code 100 times but can't find a good solution.



LinkBack URL
About LinkBacks


