Advertisement
cd62131

Dir

Mar 21st, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <dirent.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. int main(int argc, char **argv) {
  6.   DIR *d;
  7.   struct dirent *child;
  8.   if (argc != 3) exit(1);
  9.   if ((d = opendir(argv[1])) == NULL) exit(1);
  10.   while ((child = readdir(d)) != NULL) {
  11.     if (child->d_type == DT_REG && strstr(child->d_name, argv[2])) printf("%s\n", child->d_name);
  12.   }
  13.   closedir(d);
  14.   return 0;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement