Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <dirent.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <string.h>
- #include <ctype.h>
- int main(int argc, char **argv){
- DIR *openDir = opendir(argv[1]);
- if (!openDir)
- return 0;
- int n1=0, n2=0;
- char fileName[PATH_MAX];
- struct stat buf;
- struct dirent *curFile;
- while ((curFile = readdir(openDir))){
- if (!strcmp(".", curFile->d_name) && !strcmp("..", curFile->d_name))
- continue;
- snprintf(fileName, PATH_MAX, "%s/%s", argv[1], curFile->d_name);
- if (lstat(fileName, &buf)!=-1 && S_ISREG(buf.st_mode)){
- if (strchr(curFile->d_name, '.'))
- n1 += buf.st_size;
- else
- n2 += buf.st_size;
- }
- }
- printf("%d %d\n", n2, n1);
- closedir(openDir);
- return 0;
- }
Add Comment
Please, Sign In to add comment