Advertisement
Guest User

all

a guest
Nov 24th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. #define _XOPEN_SOURCE 500
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <errno.h>
  6. #include <ftw.h>
  7.  
  8. int count(const char *pathname, const struct stat *sb, int typeflag, struct FTW *buf);
  9. int files, directories, symbolic_link;
  10.  
  11. int main(int argc, char* argv[])
  12. {
  13.     if(argc != 2)
  14.     {
  15.         printf("No catalog to show");
  16.         return 1;
  17.     }
  18.  
  19.     int flags = FTW_CHDIR | FTW_DEPTH | FW_PHYS;
  20.  
  21.     nftw(argv[1], count, 5, flags);
  22.  
  23.     int sum = files + directories + symbolic_link;
  24.  
  25.     printf("Wszystkich plikow in %s: %d\n", argv[1], sum);
  26.     printf("%d plikow normalnych %d%% udzialu\n", files, 100 * files/sum);
  27.     printf("%d katalogow %d%% udzialu\n", directories, 100 * directories/sum);
  28.     printf("%d dowiazan symbolicznych %d%% udzialu\n", symbolic_link, 100 * symbolic_link/sum);
  29.  
  30.     return 0;
  31. }
  32.  
  33. int count(const char *pathname, const struct stat *sb, int typeflag, struct FTW *buf)
  34. {
  35.         printf("%d\n", typeflag);
  36.         if(typeflag == FTW_F)
  37.             files++;
  38.  
  39.         else if(typeflag == FTW_D)
  40.             directories++;
  41.  
  42.         else if(typeflag == FTW_SL)
  43.             symbolic_link++;
  44.  
  45.         else if(typeflag == FTW_DP)
  46.             ++directories;
  47.  
  48.         else if(typeflag == FTW_SLN)
  49.             ++symbolic_link;
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement