How to extract the data files from folders and subfolders
<ol>
<li><p>I am having a problem with reading the files and subfolders. My code reads fine for the given fixed source path, <code>E:\\Folder\\test\\test2</code>.</p></li>
<li><p>There are many folders in the test, like test2, test3, test4, etc. I want to extract the data files in the main folder, <code>test</code>.</p></li>
<li><p>For example, I want to extract the files in test, so I want to read all the files contained in the test instead of writing my code for test3, test4 and many. And I want to extract and write all the files as same source structure on another drive.</p></li>
<li><p>like, if the source structure is like <code>E:\\Folder\\test\\test2</code> then the destination structure should be like <code>C:\\Folder\\test\\test2</code></p></li>
</ol>

<p>Is there any way to do this?</p>

<p>Here is my code,</p>

<pre><code>private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
    DateTime dt = dateTimePicker1.Value;
    txtSelectedDate.Text = dt.ToString("yyyyMMdd");
    selectedDate = txtSelectedDate.Text;
}

private void button2_Click(object sender, EventArgs e)
{
    DateTime stdate = Datetimepicker1.value;
    while (stdate &lt;= DateTime.Now)
    {
        txtSelectedDate.Text = stdate.ToString("yyyyMMdd");
        selectedDate = txtSelectedDate.Text;
        string DayBgSpot = "E:\\Folder\\test\\test2";
        string DayBgSpotDestination = "E:\\Folder1";
        int DT = int.Parse(txtSelectedDate.Text);
        FileReader Reader = new FileReader();
        FileReader Reader1 = new FileReader();
        Reader.OpenDirectory(DayBgSpot);
        Reader.ReadNaster();
        string path = DayBgSpotDestination + "\\" + txtSelectedDate.Text + ".txt";
        StreamWriter Strwriter = new StreamWriter(path);
        try
        {
            while (Reader.iMaRecordsLeft &gt; 0)
            {
                string SecName = Reader.sMaSecName;
                string Symbol = Reader.sMaSecSymbol;
                Symbol = prefix + Symbol;
                int abc = 0;

                Reader.OpenSecurityByName(Reader.sMaSecName);
                if (Reader.iSeRecords &gt; 0)
                {
                    while (Reader.iSeRecordsLeft &gt; 0)
                    {
                        Reader.ReadDay();
                        float O = Reader.dSeo;
                        float H = Reader.dSeh;
                        float L = Reader.dSel;
                        float C = Reader.dSec;
                        double V = Reader.dSeV;
                        double OI = Reader.dSrest;
                        string T = Reader.iSeTime.ToString();
                        string D = Reader.iSeDate.ToString();
                        if (int.Parse(D) == DT)
                        {
                            string a = string.Concat(SecName, ",", Symbol, ",", D, ",", T, ",", O, ",", H, ",",  L, ",", C, ",", V, ",", OI);
                            if (SecName != "" &amp;&amp; V != 0)
                            {
                                Strwriter.WriteLine(a);
                            }
                        }
                    }
                }
                abc++;
                Reader.ReadNaster();
            }

            Reader.CloseDirectory();
            Strwriter.Close();
            Strwriter.Dispose();
        }
        catch
        {
        }
        stdate = stdate.AddDays (1); // It will get next date till present
    }
}
</code></pre>
