readdir.c 449 B

1234567891011121314151617181920
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include <stdio.h>
  4. #include <dirent.h>
  5. #include <fcntl.h>
  6. int main(int argc, char ** argv)
  7. {
  8. struct dirent * dirent;
  9. DIR * dir = opendir(".");
  10. while ((dirent = readdir(dir)))
  11. printf("found %s\n", dirent->d_name);
  12. closedir(dir);
  13. return 0;
  14. }