Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <dirent.h>
  4.  
  5. int main(int argc, char** argv)
  6. {
  7.     DIR *dp;
  8.     struct dirent *ep;
  9.     int counter = 0;
  10.  
  11.     if(argc != 2)
  12.     {
  13.         printf("USAGE: %s /path/to/dir\n", argv[0]);
  14.         return 0;
  15.     }
  16.  
  17.     dp = opendir(argv[1]);
  18.     if (dp != NULL)
  19.     {
  20.         while (ep = readdir(dp))
  21.         {
  22.             puts(ep -> d_name);
  23.             if(counter == 1000)
  24.                 break;
  25.  
  26.             counter++;
  27.         }
  28.         (void) closedir(dp);
  29.     }
  30.     else
  31.         perror("Couldn't open the directory.");
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement