title: How to find out if a file is a directory (optimal way)
body: <p>I am working at an OS independent file manager, and I am having a problem with properly detecting if a file is a directory or not on Windows.
  The <code>dirent</code> structure on windows doesn't appear to have a <code>DT_DIR</code> field, so I am using:</p>
  
  <pre><code>file_attributes=GetFileAttributes(ep-&gt;d_name);
  if(file_attributes &amp; FILE_ATTRIBUTE_DIRECTORY)files_list[i].is_dir=1;
  else files_list[i].is_dir=0;
  </code></pre>
  
  <p>However, this is not always accurate, as some files are marked as directories (for example, pagefile.sys). Besides, <code>GetFileAttributes</code> is rather slow if you have a lot of files.</p>
  
  <p>I also have a function:</p>
  
  <pre><code>int does_dir_exist(char *path)
  {
  DIR *dp_test;
  
  dp_test = opendir(path);
  if(dp_test)
      {
          return 1;
          closedir(dp_test);
      }
  
  return 0;
    }
  </code></pre>
  
  <p>But this is pretty slow (won't be a good idea to do it on 10000 files).</p>
  
  <p>Of course, I can combine both which would be pretty fast, but is there a better way?</p>
  
  <p>P.S. For some reason can't format the code properly for the second function.</p>