zoukankan      html  css  js  c++  java
  • C# 获取指定类型的文件

    C# 获取指定类型的文件

      

      public static List<FileInfo> getFile(string path, string extName)
      {
        List<FileInfo> lst = new List<FileInfo>();

        try
        {
          string[] dir = Directory.GetDirectories(path); //文件夹列表
          DirectoryInfo fdir = new DirectoryInfo(path);
          FileInfo[] file = fdir.GetFiles();
          //FileInfo[] file = Directory.GetFiles(path); //文件列表
          if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空
          {
            foreach (FileInfo f in file) //显示当前目录所有文件
            {
              if (extName.ToLower().IndexOf(f.Extension.ToLower()) >= 0)
            {
            lst.Add(f);
          }
        }
            foreach (string d in dir)
            {
              getFile(d, extName);//递归
            }
         }
        return lst;
        }catch (Exception ex){

          return lst;
        }
       }

  • 相关阅读:
    【u026】花园(garden)
    【BZOJ 1040】[ZJOI2008]骑士
    【t100】汤姆斯的天堂梦
    【BZOJ 1038】[ZJOI2008]瞭望塔
    【t096】树的序号
    Java Web整合开发(82)
    2 HTML解析
    T3186 队列练习2 codevs
    T3185 队列练习1 codevs
    T1191 数轴染色 codevs
  • 原文地址:https://www.cnblogs.com/woniucode/p/11512000.html
Copyright © 2011-2022 走看看