Advertisement
Lexolordan

Untitled

Dec 1st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys/stat.h>
  4. #include <sys/types.h>
  5. #include <dirent.h>
  6. #include <unistd.h>
  7. #include <fcntl.h>
  8. #include <time.h>
  9. #include <string.h>
  10.  
  11. int main(int argc, char *argv[]) {
  12.     const char * dir_path = argv[1];
  13.     int year = strtol(argv[2], NULL, 10);
  14.     int mon = strtol(argv[3], NULL, 10);
  15.     int day = strtol(argv[4], NULL, 10);
  16.     int dirfd = open(dir_path, O_RDONLY | O_DIRECTORY);
  17.     DIR *dir = fdopendir(dirfd);
  18.  
  19.     struct dirent *entry;
  20.     struct stat st;
  21.     struct tm max_tm;
  22.     memset(&max_tm, 0, sizeof(max_tm));
  23.     max_tm.tm_year = year - 1900;
  24.     max_tm.tm_mon = mon - 1;
  25.     max_tm.tm_mday = day;
  26.     max_tm.tm_isdst = -1;
  27.     time_t max_time = mktime(&max_tm);
  28.     while ((entry = readdir(dir))) {
  29.         fstatat(dirfd, entry->d_name, &st, 0);
  30.         time_t modifed = st.st_mtime;
  31.         if (modifed > max_time) {
  32.             printf("%s\n", entry->d_name);
  33.         }
  34.     }
  35.     closedir(dir);
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement