Advertisement
flavia_

getDirSize();

Apr 8th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1.  
  2. int getDirSize(char* directory)
  3. {
  4.     struct stat statbuf;
  5.     DIR *source_dir;
  6.     struct dirent *dentry;
  7.     int size=0;
  8.     char str[100];
  9.  
  10.     source_dir = opendir(directory);
  11.     while(dentry = readdir(source_dir))
  12.     {
  13.         if(dentry->d_type == 4)
  14.         {
  15.             if(dentry->d_name[0]!='.')
  16.             {
  17.                 strcpy(str, directory);
  18.                 strcat(str, "/");
  19.                 strcat(str, dentry->d_name);
  20.                 lstat(str,&statbuf);
  21.                 size+=statbuf.st_blocks * 512/args.size+getDirSize(str);
  22.                 //getDirSize(str);
  23.                 printf("size=%f\n",ceil(size));
  24.                 printf("%s\n",dentry->d_name);
  25.             }
  26.         }
  27.         else
  28.         {
  29.             strcpy(str,directory);
  30.             strcat(str,"/");
  31.             strcat(str,dentry->d_name);
  32.             lstat(str,&statbuf);
  33.             size+=statbuf.st_blocks*512/args.size;
  34.             printf("size=%f\n",ceil(size));
  35.             printf("%s\n",dentry->d_name);
  36.         }
  37.     }
  38.  
  39.     return size;
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement