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