/// <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); }
public static FileSystemSite EnsureSiteDirectoryPathIsDirectoryIndicated(this FileSystemSite site, IStringlyTypedPathOperator stringlyTypedPathOperator) { var directoryPathIsDirectoryIndicated = stringlyTypedPathOperator.IsDirectoryIndicatedPath(site.DirectoryPath); if (directoryPathIsDirectoryIndicated) { return(site); } else { var directoryIndicatedDirectoryPath = stringlyTypedPathOperator.EnsureDirectoryPathIsDirectoryIndicated(site.DirectoryPath); var output = new FileSystemSite(directoryIndicatedDirectoryPath, site.FileSystemOperator); return(output); } }