/// <summary> /// Produces paths where directory paths are directory-indicated, and file paths are file-indicated. /// Returns all file-entries in sorted order. /// </summary> /// <remarks> /// This method involves two calls to the file-system via <see cref="Directory.EnumerateDirectories(string, string, SearchOption)"/> and <see cref="Directory.EnumerateFiles(string, string, SearchOption)"/>. /// </remarks> public static IEnumerable <string> EnumerateFileSystemEntryPaths(IStringlyTypedPathOperator stringlyTypedPathOperator, string directoryPath, bool recursive = false) { var directoryExists = stringlyTypedPathOperator.ExistsDirectoryPath(directoryPath); if (!directoryExists) { return(Enumerable.Empty <string>()); } var searchOption = SearchOptionHelper.RecursiveToSearchOption(recursive); var subDirectoryPaths = Directory.EnumerateDirectories(directoryPath, SearchPatternHelper.All, searchOption); var filePaths = Directory.EnumerateFiles(directoryPath, SearchPatternHelper.All, searchOption); var allPaths = new List <string>(); foreach (var subDirectoryPath in subDirectoryPaths) { // Directory paths are NOT directory-indicated coming from the Directory.EnumerateDirectories() API. var outputDirectoryPath = stringlyTypedPathOperator.EnsureDirectoryPathIsDirectoryIndicated(subDirectoryPath); allPaths.Add(outputDirectoryPath); } // File paths ARE file-indicated (not directory-indicated) from from the Directory.EnumerateFiles() API. allPaths.AddRange(filePaths); // Sort file paths to return them in order. allPaths.Sort(); return(allPaths); }
/// <summary> /// Uses <see cref="Directory.EnumerateFileSystemEntries(string, string, SearchOption)"/> to get directory file-system entries. /// This method does not return directory-indicated directory paths. /// </summary> /// <remarks> /// This method involves just one call to the file-system via the <see cref="Directory"/> API. /// </remarks> public static IEnumerable <string> EnumerateFileSystemEntryPathsSimple(string directoryPath, bool recursive = false) { var searchOption = SearchOptionHelper.RecursiveToSearchOption(recursive); var enumeratedPaths = Directory.EnumerateFileSystemEntries(directoryPath, SearchPatternHelper.All, searchOption); return(enumeratedPaths); }