Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <dirent.h>
- #include <string.h>
- #include <limits.h>
- int main(int argc, char *argv[])
- {
- struct dirent *ent;
- char filename[PATH_MAX + 1];
- long long sum_size = 0;
- DIR *directory;
- struct stat buf;
- directory = opendir(argv[1]);
- while ((ent = readdir(directory))){
- sprintf(filename, "%s/%s", argv[1], ent -> d_name);
- if (lstat(filename, &buf) ==-1)
- continue;
- if ((S_ISREG(buf.st_mode)) && (!S_ISLNK(buf.st_mode)))
- sum_size += buf.st_size;
- }
- closedir(directory);
- printf("lld\n", sum_size);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement