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

  • 相关阅读:
    Linux shell 学习总结
    linux shell 比较总结
    NSURL基本操作 HA
    Mac node.js install HA
    nodejs学习资料收集 HA
    xcode技巧 HA
    google web app/enxtions 学习资料收集 HA
    Failed to upload *.app on Device 可能的解决方法 HA
    iphone开发常见问题小集2 HA
    cocos2d收集 HA
  • 原文地址:https://www.cnblogs.com/woniucode/p/11512000.html
Copyright © 2011-2022 走看看