C trouble with stat -


in program stat working current directory. can 1 please me this.

even though passing parameter main working current directory. , source path printing correct path have passed main.

    dir *dr;     struct dirent *cur;     struct stat fi;     long int total_size = 0;     dr = opendir(source);     char *name;     printf("%s\n\n\n", source);     if (!(dr))     {        perror("opendir()");        return(1);     }      while (cur = readdir(dr))     {         if(cur->d_name[0] != '.')         {             if(stat(cur->d_name, &fi) == -1)             {                 printf("error \n\n");             }             else             {                 printf("%s  ",cur->d_name);                 printf("%ld  ",fi.st_blocks);                 total_size = total_size + fi.st_blocks;             }         }     }     printf("\n\ntotal_size = %ld \n", total_size);     printf("\n\n\n");     return 0; 

}

cur->d_name contains file name.

to 'stat()' outside current directory,

need prefix path string.

also need check if returned struct readdir() file or sub directory.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -