读取选取的文件夾下的所有.txt文件
private void button1_Click(object sender, EventArgs e)
{ if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { string foldPath = folderBrowserDialog1.SelectedPath; MessageBox.Show("已选择文件夹:" + foldPath, "选择文件夹提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //获取该目录下的文件
string[] files = System.IO.Directory.GetFiles(@foldPath+"\", "*.txt", System.IO.SearchOption.TopDirectoryOnly);
foreach (var f in files) { Console.WriteLine(f); } } }
获取文件的文件名:Path.GetFileNameWithoutExtension(f)