Possible Duplicate:
count number of files with a given extension in a directory - C++?
How to get the number of files in the specific folder using c or c++ function? Is there any c library function that could get the number of files in a given directory?
Here is a working example of opendir/readdir/closedir use (no recursion here):
void listdir(char *dir) {
struct dirent *dp;
DIR *fd;
if ((fd = opendir(dir)) == NULL) {
fprintf(stderr, "listdir: can't open %s\n", dir);
return;
}
while ((dp = readdir(fd)) != NULL) {
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
continue; /* skip self and parent */
printf("%s/%s\n", dir, dp->d_name);
}
closedir(fd);
}