Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. int getBlockSize(char* directory) {
  2. int size = 0;
  3.  
  4. DIR *d;
  5. struct dirent *dir;
  6. struct stat fileStat;
  7. d = opendir(directory);
  8. if (d) {
  9. while ((dir = readdir(d)) != NULL) {
  10. if (dir->d_name[0] != '.') { // Ignore hidden files
  11. // Create the path to stat
  12. char info_path[PATH_MAX + 1];
  13. strcpy(info_path, directory);
  14. if (directory[strlen(directory) - 1] != '/')
  15. strcat(info_path, "/");
  16. strcat(info_path, dir->d_name);
  17.  
  18. stat(info_path, &fileStat);
  19.  
  20. size += fileStat.st_blocks;
  21. }
  22. }
  23. }
  24.  
  25. return size;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement