Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <dirent.h>
- #include <limits.h>
- #include <stddef.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- void traverse(const char *dir1, long long maxsize, int depth) {
- struct stat st;
- if (lstat(dir1, &st) == -1) {
- return;
- }
- if (S_ISREG(st.st_mode) && st.st_size <= maxsize) {
- printf("%s\n", dir1 + strlen("static/001.dir/"));
- } else if (S_ISDIR(st.st_mode) && depth < 4) {
- DIR *dir = opendir(dir1);
- if (dir == NULL) {
- return;
- }
- struct dirent *entry;
- while ((entry = readdir(dir)) != NULL) {
- if (strcmp(entry->d_name, "..") == 0 ||
- strcmp(entry->d_name, ".") == 0) {
- continue;
- }
- char newdir[PATH_MAX];
- snprintf(newdir, sizeof(newdir), "%s/%s", dir1, entry->d_name);
- traverse(newdir, maxsize, depth + 1);
- }
- closedir(dir);
- }
- }
- int main(int argc, char *argv[]) {
- const char *dir = argv[1];
- long long maxsize = strtoll(argv[2], NULL, 10);
- traverse(dir, maxsize, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement