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

  • 相关阅读:
    HDU 1978 How many ways
    hdu 1966 Pie
    hdu 1966 Pie
    HDU 1896 Stones
    HDU 1896 Stones
    hdu 1278 逃离迷宫
    hdu 1278 逃离迷宫
    HDU 2548 A strange lift
    HDU 2548 A strange lift
    PHP 错误与异常 笔记与总结(10)错误处理器测试
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090591.html
Copyright © 2011-2022 走看看