title: Combine multiple files into single file
body: <p>Code:</p>
  
  <pre><code>static void MultipleFilesToSingleFile(string dirPath, string filePattern, string destFile)
  {
      string[] fileAry = Directory.GetFiles(dirPath, filePattern);
  
      Console.WriteLine("Total File Count : " + fileAry.Length);
  
      using (TextWriter tw = new StreamWriter(destFile, true))
      {
          foreach (string filePath in fileAry)
          {
              using (TextReader tr = new StreamReader(filePath))
              {
                  tw.WriteLine(tr.ReadToEnd());
                  tr.Close();
                  tr.Dispose();
              }
              Console.WriteLine("File Processed : " + filePath);
          }
  
          tw.Close();
          tw.Dispose();
      }
  }
  </code></pre>
  
  <p>I need to optimize this as its extremely slow: takes 3 minutes for 45 files of average size 40 — 50 Mb XML file.</p>
  
  <p>Please note: 45 files of an average 45 MB is just one example, it can be <code>n</code> numbers of files of <code>m</code> size, where <code>n</code> is in thousands &amp; <code>m</code> can be of average 128 Kb. In short, it can vary.</p>
  
  <p>Could you please provide any views on optimization?</p>