Advertisement
pasholnahuy

Untitled

May 25th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <dirent.h>
  2. #include <limits.h>
  3. #include <stddef.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <sys/stat.h>
  8.  
  9. void traverse(const char *dir1, long long maxsize, int depth) {
  10. struct stat st;
  11. if (lstat(dir1, &st) == -1) {
  12. return;
  13. }
  14. if (S_ISREG(st.st_mode) && st.st_size <= maxsize) {
  15. printf("%s\n", dir1 + strlen("static/001.dir/"));
  16. } else if (S_ISDIR(st.st_mode) && depth < 4) {
  17. DIR *dir = opendir(dir1);
  18. if (dir == NULL) {
  19. return;
  20. }
  21. struct dirent *entry;
  22. while ((entry = readdir(dir)) != NULL) {
  23. if (strcmp(entry->d_name, "..") == 0 ||
  24. strcmp(entry->d_name, ".") == 0) {
  25. continue;
  26. }
  27. char newdir[PATH_MAX];
  28. snprintf(newdir, sizeof(newdir), "%s/%s", dir1, entry->d_name);
  29. traverse(newdir, maxsize, depth + 1);
  30. }
  31. closedir(dir);
  32. }
  33. }
  34.  
  35. int main(int argc, char *argv[]) {
  36. const char *dir = argv[1];
  37. long long maxsize = strtoll(argv[2], NULL, 10);
  38. traverse(dir, maxsize, 0);
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement