title: How to find specific files in certain directories?
body: <p>I have been stuck about how to approach verifying if a directory exists and to search for a specific file if it does. I have made various attempts, but so far my biggest obstacle has been maintaining security through access modifiers whilst retaining the modular nature of what I'm trying to accomplish.
  Goals of the code below:</p>
  
  <ul>
  <li>Get the user's drives to search for a specific directory.</li>
  <li>Search the drives to find the user's steam directory.</li>
  <li>Look for various executable(s); in this case, the three latest Elder Scrolls games.</li>
  <li>Once those have been detected and verified, perform various actions (launch, check for problems, etc etc)</li>
  </ul>
  
  <p>Yes, I know these things already exist, but I just wanted to get some perspectives on how to perform tasks of this nature. Feel free to offer suggestion and comments of constructive nature about what should be changed, all others will be ignored.</p>
  
  <pre><code>       private void button1_Click(object sender, EventArgs e)
         {
             string[] drives = Directory.GetLogicalDrives();
             foreach (string d in drives)
             {
                 TW_Detection.IDetection.arLoop((File.Exists(d + sd + g)) ? MessageBox.Show(gn + " has been detected in " + d + sd + g).ToString() : MessageBox.Show("The game was not detected!").ToString());
             }
          }
       }
    }
  </code></pre>
  
  <p>The next section of code is my attempt in various ways to create the shortest possible way to perform a series of automated directory searches to find the executable(s).</p>
  
  <pre><code>    #region initialDetection
      public class initialDetection
      {
          private string[] games = { "morrowind\\Morrowind.exe", "oblivion\\Oblivion.exe", "skyrim\\TESV.exe" };
          private string[] games_names = { "The Elder Scrolls III: Morrowind", "The Elder Scrolls IV: Oblivion", "The Elder Scrolls V: Skyrim" };
          private string[] steamDirectories = { "Program Files\\steam\\steamapps\\common", "Program Files (x86)\\steam\\steamapps\\common", "steam\\steamapps\\common" };
          private void arLoop()
          {
              for (int i = 0; i &lt; 2; i++)
              {
                 string g = games[i];
                 string gn = games[i];
              }
              for (int i = 0; i &lt; 2; i++)
              {
                 string sd = steamDirectories[i];
              }
           }
        }
      #endregion
  
      #region initialDetection
      public class gameDetection : steamDetection
      {
          private string[] games = { "morrowind\\Morrowind.exe", "oblivion\\Oblivion.exe", "skyrim\\TESV.exe" };
          private string[] games_names = { "The Elder Scrolls III: Morrowind", "The Elder Scrolls IV: Oblivion", "The Elder Scrolls V: Skyrim" };
          public partial void arLoop()
          {
              for (int i = 0; i &lt; 2; i++)
              {
                 string g = games[i];
                 string gn = games_names[i];
              }
          }
       }
      #endregion
  
      #region precompileDetection
      public class precompileDetection : gameDetection
      {
          static string completeDirectory()
          {
             arLoop();
          }
       }
      #endregion
  
      #region steamDetection
      public class steamDetection
      {
          private string[] steamDirectories = { "Program Files\\steam\\steamapps\\common\\", "Program Files (x86)\\steam\\steamapps\\common\\", "steam\\steamapps\\common\\" };
          public partial void arLoop()
          {
              for (int i = 0; i &lt; 2; i++)
              {
                 string sd = steamDirectories[i];
              }
          }
       }
      #endregion
  
      #region Detection Interface
      public interface IDetection
      {
          void arLoop();
      }
      #endregion
   }
  </code></pre>
  
  <p>Yes, I realize this code is very messy and contains a lot uneccessary and broken solutions that are a result of my experimentation. The problem in lies with being able to use the results from the detection to show in a message box that tells the user either the game hasn't been detected or it has and then show the name of the game has been detected. </p>