title: stat() giving wrong directory size in c
body: <p>I need to find the size of a file or a directory whatever given in the commandline using stat(). It works fine for the files (both relative and absolute paths) but when I give a directory, it always returns the size as 512 or 1024. </p>
  
  <p>If I print the files in the directory it goes as follows : </p>
  
  <pre><code> Name : .
   Name : ..
   Name : new
   Name : new.c
  </code></pre>
  
  <p>but only the new and new.c files are actually in there. For this, the size is returned as 512 even if I place more files in the directory.
  Here s my code fragment:</p>
  
  <pre><code>if (stat(request.data,&amp;st)&gt;=0){
          request.msgType = (short)0xfe21;
          printf("\n Size : %ld\n",st.st_size);
          sprintf(reply.data,"%ld",st.st_size);
          reply.dataLen = strlen(reply.data);
      }
      else{
          perror("\n Stat()");
      }
  }
  </code></pre>
  
  <p>Where did I go wrong???</p>
  
  <p>here is my request, reply structure:</p>
  
  <pre><code> struct message{
          unsigned short msgType;
          unsigned int offset;
          unsigned int serverDelay;
          unsigned int dataLen;
          char data[100];
      };
  struct message request,reply;
  </code></pre>
  
  <p>I run it in gcc compiler in unix os.</p>