Advertisement
Egor_Vakar

Aktios 5.2 (C)

Dec 19th, 2022 (edited)
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/stat.h>
  3. #include <dirent.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6.  
  7. int searchForDirectory(char *name);
  8. FILE *outputFile;
  9. int minSize = 0;
  10. int maxSize = 0;
  11. long minDate = 0;
  12. long maxDate = 0;
  13.  
  14. int main(__attribute__((unused)) int argc, char *argv[])
  15. {
  16.     outputFile = fopen(argv[2], "w");
  17.     minSize=atoi(argv[3]);
  18.     maxSize=atoi(argv[4]);
  19.     minDate=atol(argv[5]);
  20.     maxDate=atol(argv[6]);
  21.  
  22.     searchForDirectory(argv[1]);
  23.     fclose(outputFile);
  24.     return 0;
  25. }
  26.  
  27. int searchForDirectory(char *name)
  28. {
  29.     char directoryPath[256];
  30.     char newPath[256];
  31.     DIR *dirOne;
  32.     struct dirent *d1;
  33.     struct stat stat1;
  34.  
  35.     dirOne=opendir(name);
  36.     d1=readdir(dirOne);
  37.  
  38.     strcpy(directoryPath, name);
  39.     strcat(directoryPath, "/");
  40.  
  41.     while (d1 != NULL)
  42.     {
  43.         if (d1->d_type == DT_DIR)
  44.         {
  45.             if ((strcmp(d1->d_name, ".") != 0) && (strcmp(d1->d_name, "..") != 0))
  46.             {
  47.                 strcpy(newPath, directoryPath);
  48.                 strcat(newPath, d1->d_name);
  49.                 searchForDirectory(newPath);
  50.             }
  51.         }
  52.         d1 = readdir(dirOne);
  53.     }
  54.  
  55.     rewinddir(dirOne);
  56.     d1=readdir (dirOne);
  57.     while (d1 != NULL)
  58.     {
  59.         if (d1->d_type == DT_REG)
  60.         {
  61.             strcpy(newPath, name);
  62.             strcat(newPath, d1->d_name);
  63.  
  64.             stat(newPath, &stat1);
  65.             if (((stat1.st_size) >= minSize) && ((stat1.st_size) <= maxSize))
  66.             {
  67.                 if (((stat1.st_mtime) >= minDate) && ((stat1.st_mtime) <= maxDate))
  68.                 {
  69.                     fprintf(outputFile, "%s  %d1  %d1\n", newPath, stat1.st_size, stat1.st_mtime);
  70.                     printf("%s  %d1  %d1\n", newPath, stat1.st_size, stat1.st_mtime);
  71.                 }
  72.             }
  73.         }
  74.         d1 = readdir(dirOne);
  75.     }
  76.     closedir(dirOne);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement