title: Get all files with a certain pattern c++ linux vs. windows
body: <p>I'm trying to get all of the file with a certain pattern from a specific directory.<br>
  <strong>for example "ia_aiq_usecase_*.bin" from "c:\temp"</strong></p>
  
  <p>my windows code works fine. 
  however in linux I do not want to use boost. and I can't seem to find a way to get all the files with a certain pattern. <br>
  Can you please help ?</p>
  
  <p>Is there a way to do it cross platform?</p>
  
  <pre><code>const std::vector&lt;std::string&gt; OS::GetAllFiles(std::string directoryPath, std::string filePattern)
  {
  #ifdef _WIN32
      std::vector&lt;std::string&gt; files;
      std::string pathAndPattern = directoryPath + OS::PathSeperator() + filePattern;
      WIN32_FIND_DATA fd;
      HANDLE hFind = ::FindFirstFile(ToWString(pathAndPattern).c_str(), &amp;fd);
      if (hFind != INVALID_HANDLE_VALUE) 
       {
          do
          {
              if (!(fd.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY))
              {
                  files.push_back(FromWString(fd.cFileName));
              }
          } 
          while (::FindNextFile(hFind, &amp;fd));
          {
              ::FindClose(hFind);
          }
      }
      return files;
  #else
      std::vector&lt;std::string&gt; files;
      std::string search_path = directoryPath + OS::PathSeperator() + filePattern;
      DIR *dp;
      struct dirent *dirp;
      if ((dp = opendir(directoryPath.c_str())) == NULL)
      {
          std::cout &lt;&lt; "Error(" &lt;&lt; errno &lt;&lt; ") opening " &lt;&lt; directoryPath &lt;&lt; std::endl;
          return errno;
      }
  
      while ((dirp = readdir(dp)) != NULL) {
          files.push_back(string(dirp-&gt;d_name));
      }
      closedir(dp);
      return 0;
  #endif
  }
  </code></pre>