首先要引入命名空间:using System.IO;
在写读取方法:
DirectoryInfo dir = new DirectoryInfo(path); //path为某个目录,如: “D:\Program Files”
FileInfo[] inf = dir.GetFiles();
foreach (FileInfo finf in inf)
{
if( finf.Extension.Equals(".xml")) //如果扩展名为“.xml”
this.label1.Text += finf.FullName+"; "; //读取文件的完整目录和文件名
}
另外,还可以调用FileInfo对象的其他方法如:MoveTo(),Delete(),等方法,对文件进行移动、删除、复制等操作。

相关文章:

  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2022-02-08
  • 2021-10-22
  • 2022-12-23
猜你喜欢
  • 2021-11-09
  • 2021-08-01
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案