title: How to display all files with dirent and stat structs in C
body: <p>OK, so I'm trying to display all files within a given path-name.
  For the first path I enter, all files display correctly. 
  However, when I use a sub-directory path as an argument to the function, it only
  displays a single executable (there are other files in the sub-directory as a test).
  I absolutely cannot figure out why this is happening.
  I will post the relevant snippets of code below, any help with this would be greatly 
  appreciated.</p>
  
  <pre><code>struct dirent *directory;
  DIR *pdirectory;
  struct stat fileinfo;
  
  
  
  
  pdirectory=opendir(path);
      if (pdirectory==NULL)
      {
              printf("Error: Unable to open directory\n");
              exit(0);
      }
      printf("%s\n",path);
      while ((directory=readdir(pdirectory)) != NULL)
      {
  
          if (!stat(directory-&gt;d_name,&amp;fileinfo))
          {
              if (S_ISREG(fileinfo.st_mode))
              { 
                printf("File Name:              %s\n",directory-&gt;d_name); 
                printf("File Size:              %d bytes\n",fileinfo.st_size);
                printf("Last Access:            %s\n",ctime(&amp;fileinfo.st_atime));
              }
              }
  
  
      }
          closedir(pdirectory);
     }
  </code></pre>