c#打开一个文件夹怎么获得文件夹里的所有子文件夹并自动找到里面的txt文件?
发布网友
发布时间:2022-05-16 04:03
我来回答
共1个回答
热心网友
时间:2023-10-10 19:30
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);
}
}
效果图: