FolderBrowserDialog dialog = new FolderBrowserDialog();
if (dialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
string _path = dialog.SelectedPath;
if (_path.Length > 0)
{
string[] _txtFiles = Directory.GetFiles(_path, "*.txt", SearchOption.AllDirectories);
ListBox lstBox = new ListBox();
lstBox.Location = new Point(100, 100);
lstBox.Size = new System.Drawing.Size(300, 200);
lstBox.BringToFront();
lstBox.Items.AddRange(_txtFiles);
this.Controls.Add(lstBox);
}
}
效果图: