desdemona

rozmiar pliku so lab 11.12.2012

Dec 11th, 2012
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "sys/types.h"
  3. #include "sys/stat.h"
  4. #include "dirent.h"
  5. #include "errno.h"
  6. #include "string.h"
  7. #include "stdlib.h"
  8.  
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.     DIR *pDIR;
  13.     struct dirent *pDirEnt;
  14.     struct stat statbuffer;
  15.     int i = 0;
  16.     pDIR=opendir(".");
  17.     if(pDIR==NULL)
  18.     {
  19.         fprintf(stderr, "%d: opendir() failed (%s)\n", __FILE__, __LINE__, strerror(errno));
  20.         exit(-1);
  21.     }
  22.     pDirEnt=readdir(pDIR);
  23.     while(pDirEnt!=NULL)
  24.     {
  25.         printf("%s\t", pDirEnt->d_name);
  26.          lstat(pDirEnt->d_name, &statbuffer);
  27.         if(S_ISREG(statbuffer.st_mode)) {              
  28.                    i = (statbuffer.st_size);
  29.                    printf("rozmiar: %d \n", i);
  30.                 }
  31.                 else
  32.                 {
  33.                     printf("\n");
  34.                 }
  35.         pDirEnt=readdir(pDIR);
  36.     }
  37.    
  38.     close(pDIR);
  39.     return 0;  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment