在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/// <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; } /// <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; }
/// <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; }
|
请发表评论