c#打开一个文件夹怎么获得文件夹里的所有子文件夹并自动找到里面的txt文件?
展开全部
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);
}
}
效果图:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询