Guest User

Untitled

a guest
Dec 10th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 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. if (!openDir)
  13. return 0;
  14. int n1=0, n2=0;
  15. char fileName[PATH_MAX];
  16. struct stat buf;
  17. struct dirent *curFile;
  18. while ((curFile = readdir(openDir))){
  19. if (!strcmp(".", curFile->d_name) && !strcmp("..", curFile->d_name))
  20. continue;
  21. snprintf(fileName, PATH_MAX, "%s/%s", argv[1], curFile->d_name);
  22. if (lstat(fileName, &buf)!=-1 && S_ISREG(buf.st_mode)){
  23. if (strchr(curFile->d_name, '.'))
  24. n1 += buf.st_size;
  25. else
  26. n2 += buf.st_size;
  27. }
  28. }
  29. printf("%d %d\n", n2, n1);
  30. closedir(openDir);
  31. return 0;
  32. }
Add Comment
Please, Sign In to add comment