对于很多应用功能,有时需要获取指定目录下的指定后缀名文件以实现批处理。以下为事例代码:取到的文件放入动态数组中……
/// <summary> /// 获取某一扩展名的文件集合 /// </summary> /// <param name="dictoryName">目录名</param> /// <param name="fiterName">扩展名</param> /// <returns>文件名集合</returns> public List<string> View(string dictoryName,string fiterName) { List<string> ViewFileNameLst = new List<string>(); if (!Directory.Exists(dictoryName)) { return ViewFileNameLst; } DirectoryInfo dirInfo=new DirectoryInfo(dictoryName); FileInfo[] fileInfs= dirInfo.GetFiles(); foreach(FileInfo fInfo in fileInfs) { //过滤指定后缀名文件 if(fInfo.Name.EndsWith(fiterName)) { ViewFileNameLst.Add(System.IO.Path.GetFileNameWithoutExtension(fInfo.FullName)); } } return ViewFileNameLst; }

 

相关文章:

  • 2021-08-15
  • 2022-12-23
  • 2021-09-05
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
猜你喜欢
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
相关资源
相似解决方案