title: How to list files in a directory using the Windows API?
body: <p>I have this code and it displays the folder with the directory itself and not its contents. I want to display its contents. I don't want to use boost::filesystem.  </p>
  
  <p>How can I resolve this?</p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
      WIN32_FIND_DATA data;
      HANDLE hFind = FindFirstFile("C:\\semester2", &amp;data);      // DIRECTORY
  
      if ( hFind != INVALID_HANDLE_VALUE ) {
          do {
              std::cout &lt;&lt; data.cFileName &lt;&lt; std::endl;
          } while (FindNextFile(hFind, &amp;data));
          FindClose(hFind);
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>semester2
  </code></pre>