Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/stat.h>
- #include <dirent.h>
- #include <string.h>
- #include <stdlib.h>
- int searchForDirectory(char *name);
- FILE *outputFile;
- int minSize = 0;
- int maxSize = 0;
- long minDate = 0;
- long maxDate = 0;
- int main(__attribute__((unused)) int argc, char *argv[])
- {
- outputFile = fopen(argv[2], "w");
- minSize=atoi(argv[3]);
- maxSize=atoi(argv[4]);
- minDate=atol(argv[5]);
- maxDate=atol(argv[6]);
- searchForDirectory(argv[1]);
- fclose(outputFile);
- return 0;
- }
- int searchForDirectory(char *name)
- {
- char directoryPath[256];
- char newPath[256];
- DIR *dirOne;
- struct dirent *d1;
- struct stat stat1;
- dirOne=opendir(name);
- d1=readdir(dirOne);
- strcpy(directoryPath, name);
- strcat(directoryPath, "/");
- while (d1 != NULL)
- {
- if (d1->d_type == DT_DIR)
- {
- if ((strcmp(d1->d_name, ".") != 0) && (strcmp(d1->d_name, "..") != 0))
- {
- strcpy(newPath, directoryPath);
- strcat(newPath, d1->d_name);
- searchForDirectory(newPath);
- }
- }
- d1 = readdir(dirOne);
- }
- rewinddir(dirOne);
- d1=readdir (dirOne);
- while (d1 != NULL)
- {
- if (d1->d_type == DT_REG)
- {
- strcpy(newPath, name);
- strcat(newPath, d1->d_name);
- stat(newPath, &stat1);
- if (((stat1.st_size) >= minSize) && ((stat1.st_size) <= maxSize))
- {
- if (((stat1.st_mtime) >= minDate) && ((stat1.st_mtime) <= maxDate))
- {
- fprintf(outputFile, "%s %d1 %d1\n", newPath, stat1.st_size, stat1.st_mtime);
- printf("%s %d1 %d1\n", newPath, stat1.st_size, stat1.st_mtime);
- }
- }
- }
- d1 = readdir(dirOne);
- }
- closedir(dirOne);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement