• C# 返回指定目录下所有文件信息


    •  返回指定目录下所有文件信息 
            /// <summary>  
            /// 返回指定目录下所有文件信息  
            /// </summary>  
            /// <param name="strDirectory">目录字符串</param>  
            /// <returns></returns>  
            public List<FileInfo> GetAllFilesInDirectory(string strDirectory)
            {
                List<FileInfo> listFiles = new List<FileInfo>(); //保存所有的文件信息  
                DirectoryInfo directory = new DirectoryInfo(strDirectory);
                DirectoryInfo[] directoryArray = directory.GetDirectories();
                FileInfo[] fileInfoArray = directory.GetFiles();
                if (fileInfoArray.Length > 0) listFiles.AddRange(fileInfoArray);
                foreach (DirectoryInfo _directoryInfo in directoryArray)
                {
                    DirectoryInfo directoryA = new DirectoryInfo(_directoryInfo.FullName);
                    DirectoryInfo[] directoryArrayA = directoryA.GetDirectories();
                    FileInfo[] fileInfoArrayA = directoryA.GetFiles();
                    if (fileInfoArrayA.Length > 0) listFiles.AddRange(fileInfoArrayA);
                    GetAllFilesInDirectory(_directoryInfo.FullName);//递归遍历  
                }
                return listFiles;
            }
  • 相关阅读:
    XML约束之DTD
    XML基础
    向方法传递多个参数
    从方法里返回值
    给方法传值
    对象状态和行为
    对象类型数组
    数组
    避开关键字
    primitive数据类型
  • 原文地址:https://www.cnblogs.com/hcyblogs/p/6639703.html
Copyright © 2020-2023  润新知