I've been trying for a few days now to write a code which will inspect all subfolders from C:\Users, and print their files, for example:
C:\Users\Public
files
C:\Users\Somefolder
files
Here is my code:
main() {
DIR *dr,*dirp;
struct dirent *dr_ent,*sec;
char *buf,*baf;
char get[50],x[50];
char folder[] = "C:\\Users\\";
dr = opendir(folder);
if (dr != NULL)
goto next;
else return -1;
next:
while ((dr_ent = readdir(dr))!=NULL) {
buf=dr_ent->d_name;
strcpy(get,buf);
if (strstr(get,".")==NULL && strstr(get,"..")==NULL) {
strcpy(x,folder);
strcat(x,get);
printf("%s\n",x);
continue;
goto read;
Sleep(300);
}
}
read:
dirp = opendir(get);
while ((sec = readdir(dirp))!=NULL) {
baf=sec->d_name;
printf("%s\n",baf);
Sleep(300);
}
system("PAUSE");
return EXIT_SUCCESS;
}`enter code here`
And in this case, only one folder was read. So am I actually making mistake by taking a variable from loop before so only one line was taken? And why is second label completely ignored by program? By the way, I'm sort of beginner in C programming, so don't get surprised by potential errors.