title: Error in Listing File from Directory in C++
body: <p>I am having a problem with my code. Whenever i run the program, the last file search would return a zero value where in it shouldn't.</p>
  
  <p>here is the code:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;iostream&gt; 
  #include &lt;conio.h&gt;
  
  using namespace std;
  
  string GetPath(string path){
          char directory[1024];
          vector &lt;string&gt; filelist;
          strcpy_s(directory,path.c_str());
          BOOL checker;
  
              WIN32_FIND_DATA findFileData;
              HANDLE hFind = FindFirstFile((LPCSTR)directory, &amp;findFileData);
              cout &lt;&lt;"Files in:" &lt;&lt;"\n"&lt;&lt;directory&lt;&lt;"\n"&lt;&lt;endl;
              checker = FindNextFile(hFind, &amp;findFileData);
  
              while(checker)
              {
                  checker = FindNextFile(hFind, &amp;findFileData);
                  filelist.push_back(findFileData.cFileName);//save file list in vector
                  cout &lt;&lt; findFileData.cFileName &lt;&lt; endl;
              }
  
              DWORD error = GetLastError();
              if( error != ERROR_NO_MORE_FILES)
              {
  
              }
              /*for (unsigned i=1;i&lt;filelist.size();i++){
                  cout &lt;&lt; filelist[i]&lt;&lt;endl;//print out the vector
              }*/
  
  
              return 0;
  }
  
  int main()
  {
     string path;
     path="C:\\Program Files\\*.*";
     vector &lt;string&gt; handler;
     path = GetPath(path);
  }
  </code></pre>