title: Utilizing the <filesystem> library; visualStudios
body: <p>I'll cut the the short of it. I'm attempting to understand the filesystem library but there's very little information I've been able to find. I managed to get it to compile and understand the filesystem::path type variable really well but don't seem to understand how to get filesystem::directory_iterator to work properly. I'm not sure if I'm using it for a purpose it wasn't design for. So here is what I'm attempting to do:</p>
  
  <p>I wanted to create a program that opens every text file within a specified folder. For this I need to obtain the folder name and path but I want the program to be able to obtain this information on itself and dynamically so if I add or remove textFiles it'll have the logic to function.</p>
  
  <p>I'm able to create a directory_iterator variable that it manages to hold the first file with me just giving it the directory like this:</p>
  
  <pre><code>const char address[]{ "C:\\Users\\c-jr8\\ProgramBranch\\PersonalPlatform\\log extruder\\logs" };
  
  fs::directory_iterator myIterator(address);
  </code></pre>
  
  <p>When testing the code in the folder I have four textFiles called "attempt 1" to "attempt 4". When reading the information on: </p>
  
  <p><a href="https://docs.microsoft.com/en-us/cpp/standard-library/directory-iterator-class?view=vs-2019#op_star" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/cpp/standard-library/directory-iterator-class?view=vs-2019#op_star</a></p>
  
  <p>It mentions two functions to move the path object within the iterator to the next file. The first is increment(), which is the intendent method for iterating through the files, and operation++(). </p>
  
  <p>Now increment() hasn't been able to work for me cause it takes in a erro_code type variable and I haven't been able to find much information about how to implement this with the filesystem_errorcode variable or however it's meant to be used. The operation++() works beautifully and provides me with the path to every file but I was having issues with managing the code to detect when the operate++() functions leads to no other files. Once it iterates through every file it sorts of crashes when it keeps moving to the next. Here's that piece of code:</p>
  
  <pre><code>string tempString;
  for (int i = 0; i &lt; 5; i++) { //Here the limiting is 5 so it'll iterate onces more than the numbers of files unpurpose to see how it responses.
      tempString = myIterator.operator*().path().generic_string();
      ifstream tempFile(tempString);
  
      if (!tempFile.is_open()) {
          cout &lt;&lt; "Looking at file: " &lt;&lt; i + 1 &lt;&lt; "; failed to open." &lt;&lt; endl &lt;&lt; endl;
          cin.get();
          return 0;
      }
  
      {
          //do things with file...
      }
  
      tempFile.close();
      myIterator.operator++();
  }
  </code></pre>
  
  <p>What I want if to find a way to stop the for loop once it the iterator goes off the final file. </p>
  
  <p>whichever information about how the filesystem library works it would be very much appreciated.</p>