reading and writing multiple files at the same time and performing same tasks on them
<p>I am a beginner to programming. I wrote a code in C# to open a single file (that has 4 columns of data) and extract the fourth column into a list. Then did some basic work on the data to extract the mean, minimum and maximum values of the data set. Then, the results was written to dedicated files for the mean, minimum and maximum values.  </p>

<p>Now I want to repeat the same tests but for a multiple sets of files - each with over 100,000 lines of data. I want to enable the program to read a multiple set of files in the same folder and then do the same calculations for each file and compile all the results for mean, minimum and maximum values into separate folders, as before. </p>

<p>The code for the single file is as follows;</p>

<pre><code>    private void button1_Click_1(object sender, EventArgs e)
    {
        string text = "";
        DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
        // create a list to insert the data into
        List&lt;float&gt; noise = new List&lt;float&gt;();
        int count = 0;
        float sum = 0;
        float mean = 0; 
        float max = 0;
        float min = 100;

        TextWriter tw = new StreamWriter("c:/Users/a3708906/Documents/Filereader - 13062012/Filereader/date.txt");
        if (result == DialogResult.OK) // Test result.
        {
            string file = openFileDialog1.FileName;
            FileInfo src = new FileInfo(file);
            TextReader reader = src.OpenText();
            text = reader.ReadLine();

            // while the text being read in from reader.Readline() is not null

            while (text != null)
            {
                text = reader.ReadLine();
                if (text != null)
                {
                    string[] words = text.Split(',');
                    noise.Add(Convert.ToSingle(words[3]));

                    // write text to a file
                    tw.WriteLine(text);
                    //foreach (string word in words)
                    //{
                    //    tw.WriteLine(word);
                    //}
                }

            }
        }

        tw.Close();

        TextWriter tw1 = new StreamWriter("c:/Users/a3708906/Documents/Filereader - 13062012/Filereader/noise.txt");
        foreach (float ns in noise)
        {
            tw1.WriteLine(Convert.ToString(ns));
            count++;
            sum += ns;
            mean = sum/count;

            float min1 = 0; 

            if (ns &gt; max)
                max = ns;
            else if (ns &lt; max)
                min1 = ns;

            if (min1 &lt; min &amp;&amp; min1 &gt;0)
                min = min1;
            else
                min = min;

        }

        tw1.Close();

        TextWriter tw2 = new StreamWriter("c:/Users/a3708906/Documents/Filereader - 13062012/Filereader/summarymeans.txt");
        tw2.WriteLine("Mean Noise");
        tw2.WriteLine("==========");
        tw2.WriteLine("mote_noise 2: {0}", Convert.ToString(mean));
        tw2.Close();

        TextWriter tw3 = new StreamWriter("c:/Users/a3708906/Documents/Filereader - 13062012/Filereader/summarymaximums.txt");
        tw3.WriteLine("Maximum Noise");
        tw3.WriteLine("=============");    
        tw3.WriteLine("mote_noise 2: {0}", Convert.ToString(max));
        tw3.Close();

        TextWriter tw4 = new StreamWriter("c:/Users/a3708906/Documents/Filereader - 13062012/Filereader/summaryminimums.txt");
        tw4.WriteLine("Minimum Noise");
        tw4.WriteLine("=============");
        tw4.WriteLine("mote_noise 2: {0}", Convert.ToString(min));
        tw4.Close();
    }
</code></pre>

<p>I will be grateful if someone could help to translate this code for working with multiple files. Thank you.</p>
