I made a form called "Form1" and dragged a "folderBrowserDialog" from
the toolbox.  This appeared in the tray under the form.  I wanted the
user to pick a folder, and then the filenames of the folder would
appear in a listbox.  The listbox was also dragged onto "Form1".  But
the following code simply does not work.  The listbox never gets
anything in it, even though I click on a random folder in the
"folderBrowserDialog"

        private void Form1_Load(object sender, EventArgs e)
        {
            string folder;

            folderBrowserDialog1.ShowDialog();
            folder = folderBrowserDialog1.SelectedPath;
            DirSearch(folder);
        }
 void DirSearch(string sDir)
        {
            try
            {
                foreach (string d in Directory.GetDirectories(sDir))
                {
                    foreach (string f in Directory.GetFiles(d,
txtFile.Text))
                    {
                        lstFilesFound.Items.Add(f);
                    }
                    DirSearch(d);
                }
            }
            catch (System.Exception excpt)
            {
                Console.WriteLine(excpt.Message);
            }
        }

Reply via email to