Guest User

Untitled

a guest
Dec 10th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <dirent.h>
  5. #include <unistd.h>
  6. #include <sys/stat.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9.  
  10. int main(int argc, char **argv){
  11. DIR *openDir = opendir(argv[1]);
  12. int n1=0, n2=0;
  13. char fileName[PATH_MAX];
  14. struct stat buf;
  15. struct dirent *curFile;
  16. while ((curFile = readdir(openDir))){
  17. if (!strcmp(".", curFile->d_name) && !strcmp("..", curFile->d_name))
  18. continue;
  19. snprintf(fileName, PATH_MAX, "%s/%s", argv[1], curFile->d_name);
  20. if (lstat(fileName, &buf)!=-1 && S_ISREG(buf.st_mode)){
  21. if (strchr(curFile->d_name, '.'))
  22. n1 += buf.st_size;
  23. else
  24. n2 += buf.st_size;
  25. }
  26. }
  27. printf("%d %d\n", n2, n1);
  28. closedir(openDir);
  29. return 0;
  30. }
Add Comment
Please, Sign In to add comment