读取选取的文件夾下的所有.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)

相关文章:

  • 2021-09-26
  • 2022-12-23
  • 2022-02-07
  • 2022-02-06
  • 2022-12-23
  • 2022-01-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案