dirent.c 430 B

12345678910111213141516171819202122232425
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <dirent.h>
  5. int main(int argc, char **argv)
  6. {
  7. DIR *dirh;
  8. struct dirent *dirp;
  9. static char mydir[20] = "/tmp";
  10. if ((dirh = opendir(mydir)) == NULL) {
  11. perror("opendir");
  12. return 1;
  13. }
  14. for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh)) {
  15. printf("Got dir entry: %s\n",dirp->d_name);
  16. }
  17. closedir(dirh);
  18. return 0;
  19. }