How do I read from all files in a given folder?
<p>The program below parses one of the so-called RAW files of <a href="http://www.bay12forums.com/smf/index.php?board=11.0" rel="nofollow">Dwarf Fortress.</a> The code works fine, but with my current implementation, I need to run the program once for every file, manually changing the source file each time. Is there someway I could instead parse through all text files in the given folder?</p>

<p>(Do note that currently the output file is in the same folder as the input file. I'm not quite sure what would happen if the program tried to open the file it was in the middle of writing to, but it's something to bear in mind).</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // create reader &amp; open file
            string filePath = @"C:\foo\Dwarf Fortess\creature_domestic.txt";
            string destPath = @"C:\foo\Dwarf Fortess\eggCreatures.txt";
            string line;
            // 
            TextReader tr = new StreamReader(filePath);
            TextWriter tw = new StreamWriter(destPath);

            // read a line of text
            while ((line = tr.ReadLine()) != null) 
            {

                        if (line.Contains("[CREATURE:"))
                        {
                            tw.WriteLine(line);
                        }
                        if(line.Contains("[LAYS_EGGS]"))
                        {
                            tr.ReadLine();
                            tr.ReadLine();
                            tr.ReadLine();
                            tw.WriteLine(tr.ReadLine());
                            tw.WriteLine(tr.ReadLine());
                        }


            }

            // close the stream
            tr.Close();
            tw.Close();
        }
    }
}
</code></pre>
