title: C# directory.getfiles memory help
body: <p>Here is the code I’m using:</p>
  
  <pre><code>using (StreamWriter output = new StreamWriter(Path.Combine(masterdestination, "Master.txt")))
  {
       string masterfolders = sourcefolder1;
       string[] filess = Directory.GetFiles(masterfolders, "*.txt");
       foreach (string file in filess)
       {
          output.WriteLine(Path.GetFileName(file));
       }
  }  
  </code></pre>
  
  <p>This code will search for all files in a user specified directory for any txt file.  These directories sometimes contain 2million files.</p>
  
  <p>monitoring this process while it's running I’ve seen it climb up to 800MB memory usage.  Is there a way I can preserve the speed of this process and limit the memory it uses?  Or have it read and dump and continue?  Hashtable?  Any idea's would be awesome.</p>