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;
        }
       }

  • 相关阅读:
    STL源代码剖析——STL算法之set集合算法
    iOS + Nodejs SSL/Https双向认证
    C语言将10进制转为2进制
    图的遍历算法
    Web—CSS概述
    苹果新的编程语言 Swift 语言进阶(八)--属性
    UVa 10700
    C++实现KMP模式匹配算法
    软件project
    oralce GROUPING SETS
  • 原文地址:https://www.cnblogs.com/woniucode/p/11512000.html
Copyright © 2011-2022 走看看