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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -