/// <summary> /// The select files. /// </summary> /// <param name="folderPath"> /// The folder path. /// </param> /// <param name="searchMask"> /// The search mask. /// </param> /// <param name="searchMode"> /// The search mode. /// </param> /// <param name="sortMode"> /// The sort mode. /// </param> /// <returns> /// The <see cref="IEnumerable"/>. /// </returns> public static IEnumerable <string> SelectFiles( string folderPath, string searchMask = "", TreeCollectMode searchMode = 0, EntriesSortMode sortMode = 0) { var enumerable = SelectFileInfos(folderPath, searchMask, searchMode, sortMode); if (enumerable == null) { return(null); } return(from f in enumerable select f.FullName); }
/// <summary> /// The select file infos. /// </summary> /// <param name="folderPath"> /// The folder path. /// </param> /// <param name="searchMask"> /// The search mask. /// </param> /// <param name="searchMode"> /// The search mode. /// </param> /// <param name="sortMode"> /// The sort mode. /// </param> /// <returns> /// The <see cref="IEnumerable"/>. /// </returns> /// <exception cref="ArgumentException"> /// </exception> public static IEnumerable <FileInfo> SelectFileInfos( string folderPath, string searchMask = "", TreeCollectMode searchMode = 0, EntriesSortMode sortMode = 0) { IEnumerable <FileInfo> files; var bTrimFirst = true; folderPath = TStringHelper.StringToEmpty(folderPath, bTrimFirst); if (!FolderExists(folderPath)) { return(null); } var folderInfo = new DirectoryInfo(folderPath); switch (searchMode) { case TreeCollectMode.RootOnly: files = folderInfo.GetFiles(CorrectFileSearchMask(searchMask)); break; case TreeCollectMode.LeavesOnly: { var list = new List <FileInfo>(); DoCollectFinalFiles(list, folderInfo, CorrectFileSearchMask(searchMask)); files = list; break; } case TreeCollectMode.Everywhere: files = folderInfo.GetFiles(CorrectFileSearchMask(searchMask), SearchOption.AllDirectories); break; default: throw new ArgumentException(string.Format("режим поиска файлов не поддерживается: {0}", searchMode)); } switch (sortMode) { case EntriesSortMode.Unsorted: return(files); case EntriesSortMode.NameAscending: return(from f in files orderby f.FullName select f); case EntriesSortMode.NameDescending: return(from f in files orderby f.FullName descending select f); case EntriesSortMode.CreationPointAscending: return(from f in files orderby f.CreationTimeUtc select f); case EntriesSortMode.CreationPointDescending: return(from f in files orderby f.CreationTimeUtc descending select f); case EntriesSortMode.ModificationPointAscending: return(from f in files orderby f.LastWriteTimeUtc select f); case EntriesSortMode.ModificationPointDescending: return(from f in files orderby f.LastWriteTimeUtc descending select f); } throw new ArgumentException(string.Format("режим сортировки при поиске файлов не поддерживается: {0}", sortMode)); }