title: Reading multiple files one by one
body: <p>I am almost done with my project, but I still have one small thing that needs to be done...I need to run the entire program for each file in the directory.  There are about 200 files in total. Below is the main class of the program that needs to run. I'm thinking I will put the entire thing in a do-while loop and run it until there are no more .dat files in the directory, but I'm not sure if that will work. Obviously, I'd like to replace the hard-coded file names with variables...I'm just not sure how to do that, either.  Please let me know if you need clarification. I've been working on this project for a while and I'm getting kind of brain-numb. Thanks in advance for your help!</p>
  
  <p><strong>Edit</strong> My test directory is on a Windows machine, but it will be uploaded to a linux machine at school.</p>
  
  <pre><code>  int main() {
  
      NearestNeighbor face;
      //string path = "C:\Users\Documents\NetBeansProjects\CSCE350";
      //string searchPattern = "*dat";
     // string fullSearchPath = path + searchPattern;
  
  
      /*TEMPLATE DATA*/
  
      /***********************************************************************************/
      fstream templateData;
      double data = 0.0;
  
      templateData.open("003_template.dat", std::ios::in);
      //check that the file is opened
      if (!templateData.is_open()) {
          std::cerr &lt;&lt; "Template: Nooooooo!\n";
          exit(0);
      }
  
  
      /*************************************************************************************/
      //fill the templateVector with the values from templateData
      std::vector&lt;std::vector&lt;double&gt; &gt; templateVector;
      std::string line;
  
      while (getline(templateData, line, '\n'))
          templateVector.push_back(face.splitData(line));
  
      //testing the contents of the templateVector
      //  cout &lt;&lt; "TemplateVector: ";
      //   for (unsigned i = 0u; i != templateVector.size(); ++i) {
      //           
      //    std::cout &lt;&lt; "Index[" &lt;&lt; i &lt;&lt; "] ";
      //    for(double value : templateVector[i])
      //        std::cout &lt;&lt; value &lt;&lt; " ";
      //    std::cout &lt;&lt; "\n";
      //  }
  
  
      /*QUERY DATA*/
      /************************************************************************************/
      std::ifstream inFile("003_AU01_query.dat", std::ios::in);
      std::vector&lt;double&gt; queryVector;
  
      double pixel = 0.0;
  
      // Check that the file opened
      if (!inFile.is_open()) {
          std::cerr &lt;&lt; "Query: Nooooooo!\n";
          exit(1);
      }
  
      // fill the queryVector with the query data
  
      while (inFile &gt;&gt; pixel) {
          queryVector.push_back(pixel);
      }
      inFile.close();
  
      //   testing the content of the query vector
      //   for (unsigned i =0u; i &lt; pixels.size(); i++){
      //       std::cout &lt;&lt; "Index["&lt;&lt; i &lt;&lt; "] " &lt;&lt; pixels[i];
      //   }   
      //    std::cout &lt;&lt; "\n";
  
      /*OUTPUT SCALAR PRODUCT*/
      /****************************************************************************************/
      vector&lt;double&gt; theList;
  /*break out each of the vectors from the templateVector and compute the scalar product*/
      for (auto&amp; vec : templateVector) {
          int i;
          cout &lt;&lt; "\nscalar_product: Index[" &lt;&lt; i &lt;&lt; "] " &lt;&lt; face.scalar_product(vec, queryVector);
          theList.push_back(face.scalar_product(vec, queryVector));//fill theList vector with the computations
          i++;
          std::cout &lt;&lt; "\n";
  
      }
      //make sure that the sorted products are output with their original index numbers
      vector&lt;pair&lt;int, double&gt; &gt; sorted;
      sorted.reserve(theList.size());
      for(size_t i = 0.00; i != theList.size(); i++){
          sorted.push_back(make_pair(theList[i], i));
      }
     //sort the scalar products and print out the 10 closest neighbors
      face.quickSort(sorted);
      cout &lt;&lt; "\nVector after sort:\n";
      for(size_t i = 0; i &lt; 10; i++){
          cout &lt;&lt; "idx: " &lt;&lt; sorted[i].second &lt;&lt; " " &lt;&lt; "val: " &lt;&lt; sorted[i].first &lt;&lt; endl;
      }
  
  }
  </code></pre>