zoukankan      html  css  js  c++  java
  • 查询文件夹以及子文件夹下面的文件

     //获得院校相册图片,从college文件夹下查询所有子文件夹
            public List<string> ListFilesColleges(FileSystemInfo info)
            {
                List<string> image_list = new List<string>();
                if (!info.Exists) return null;
                DirectoryInfo dir = info as DirectoryInfo;
                //不是目录
                if (dir == null) return null;
                FileSystemInfo[] files = dir.GetFileSystemInfos();
                for (int i = 0; i < files.Length; i++)
                {
                    string son_folder_name = files[i].Name;//获取文件夹名称
                    DirectoryInfo dir_college = files[i] as DirectoryInfo;
                    FileSystemInfo[] file_college_name = dir_college.GetFileSystemInfos();//子文件夹里面的文件
                    if (file_college_name.Length > 0)
                    {
                        FileInfo file = file_college_name[0] as FileInfo;
                        string filename = file.Name;
                        string fileEx = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();//后缀jpg jpeg gif bmp
                        if (fileEx == "jpg" || fileEx == "jpeg" || fileEx == "gif" || fileEx == "bmp")
                        {
                            image_list.Add(son_folder_name + "/" + file.Name);
                        }
                    }
                }
                return image_list;
            }

  • 相关阅读:
    算法竞赛入门经典训练指南——UVA 11300 preading the Wealth
    hiho一下 第148周
    ajax总结及案例
    Spring事务
    Struts2拦截器介绍
    Struts2的拦截器----Dog实例
    Struts2文件的下载
    Struts2文件的上传
    Struts2类型转换
    Struts2 属性驱动、模型驱动、异常机制
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090591.html
Copyright © 2011-2022 走看看