calling multiple files in a directory
<p>in the process file method of the code below, when i try to compile the program, an error message is displayed that there is no access to the file. i am wondering why. the program is able to write the names of all the files in the selected folder. now i want the program to do the task to calculate the mean, minimum and maximum values for each file. the code is as follows; </p>

<pre><code>namespace Filereader_m_15062012
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    string[] fileEntries;

    private void Form1_Load(object sender, EventArgs e)
    {
        DialogResult result = folderBrowserDialog1.ShowDialog(); // Show the dialog.
        // create a list to insert the data into
        //put all the files in the root directory into array
        string[] fileEntries = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.csv");

        // Display all files.
        TextWriter tw1 = new StreamWriter(folderBrowserDialog1.SelectedPath + "/listoffiles.txt");

        List&lt;string&gt; filenames = new List&lt;string&gt;();
        tw1.WriteLine("--- Files: ---");
        foreach (string path in fileEntries)
        {
            tw1.WriteLine(path);
        }

        tw1.Close();

        TextWriter tw2 = new StreamWriter(folderBrowserDialog1.SelectedPath + "/errorlist.txt");
        foreach (string path in fileEntries)
        {
            if (File.Exists(path))
            {
                ProcessFile();
            }
            else
            {
                tw2.WriteLine("{0}", path);
            }

        }
    }


    public void ProcessFile()
    {
        string text = "";

        // create a list to insert the data into
        List&lt;float&gt; noise = new List&lt;float&gt;();

        TextWriter tw3 = new StreamWriter(folderBrowserDialog1.SelectedPath + "/name.txt");

        string file = folderBrowserDialog1.SelectedPath;
                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();

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

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

                        }
                    }

                    tw3.Close();
               }

                int count = 0;
                float sum = 0;
                float mean = 0;
                float max = 0;
                float min = 100;

                TextWriter tw4 = new StreamWriter(folderBrowserDialog1.SelectedPath + "/noise.txt");

                foreach (float ns in noise)
                {
                    tw4.WriteLine(Convert.ToString(ns));
                    count++;
                    sum += ns;
                    mean = sum / count;
                    float min1 = 0;
                    float min2 = 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 = min2;
                }

                tw4.Close();

                TextWriter tw5 = new StreamWriter(folderBrowserDialog1.SelectedPath + "/summarymeans.txt");
                tw5.WriteLine("Mean Noise");
                tw5.WriteLine("==========");
                tw5.WriteLine("mote_noise 2: {0}", Convert.ToString(mean));
                tw5.Close();

                TextWriter tw6 = new StreamWriter(folderBrowserDialog1.SelectedPath + "/summarymaximums.txt");
                tw6.WriteLine("Maximum Noise");
                tw6.WriteLine("=============");
                tw6.WriteLine("mote_noise 2: {0}", Convert.ToString(max));
                tw6.Close();

                TextWriter tw7 = new StreamWriter(folderBrowserDialog1.SelectedPath + "/summaryminimums.txt");
                tw7.WriteLine("Minimum Noise");
                tw7.WriteLine("=============");
                tw7.WriteLine("mote_noise 2: {0}", Convert.ToString(min));
                tw7.Close();

     }

    private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
    {

    }
</code></pre>

<p>I appreciate anybody's help to solve. is it that i am not calling the files in the appropriate manner? thanks</p>
