/// <summary> /// Returns an enumerable collection of file or directory names in a specified path. /// </summary> /// <param name="fileSystem">The file system.</param> /// <param name="path">The path of the directory to look for files or directories.</param> /// <param name="searchPattern">The search string to match against the names of directories in path. This parameter can contain a combination /// of valid literal path and wildcard (* and ?) characters (see Remarks), but doesn't support regular expressions.</param> /// <param name="searchOption">One of the enumeration values that specifies whether the search operation should include only the current directory /// or should include all subdirectories. /// The default value is TopDirectoryOnly.</param> /// <returns>An enumerable collection of the full names (including paths) for the files and directories in the directory specified by path.</returns> public static IEnumerable <UPath> EnumeratePaths(this IReadOnlyFileSystem fileSystem, UPath path, string searchPattern, SearchOption searchOption) { if (searchPattern == null) { throw new ArgumentNullException(nameof(searchPattern)); } return(fileSystem.EnumeratePaths(path, searchPattern, searchOption, SearchTarget.Both)); }
/// <summary> /// Returns an enumerable collection of <see cref="ReadOnlyFileSystemEntry"/> that match a search pattern in a specified path. /// </summary> /// <param name="fileSystem">The file system.</param> /// <param name="path">The path of the directory to look for files and directories.</param> /// <param name="searchPattern">The search string to match against the names of directories in path. This parameter can contain a combination /// of valid literal path and wildcard (* and ?) characters (see Remarks), but doesn't support regular expressions.</param> /// <param name="searchOption">One of the enumeration values that specifies whether the search operation should include only the current directory /// or should include all subdirectories. /// The default value is TopDirectoryOnly.</param> /// <param name="searchTarget">The search target either <see cref="SearchTarget.Both"/> or only <see cref="SearchTarget.Directory"/> or <see cref="SearchTarget.File"/>. Default is <see cref="SearchTarget.Both"/></param> /// <returns>An enumerable collection of <see cref="ReadOnlyFileSystemEntry"/> that match a search pattern in a specified path.</returns> public static IEnumerable <ReadOnlyFileSystemEntry> EnumerateFileSystemEntries(this IReadOnlyFileSystem fileSystem, UPath path, string searchPattern, SearchOption searchOption, SearchTarget searchTarget = SearchTarget.Both) { if (searchPattern == null) { throw new ArgumentNullException(nameof(searchPattern)); } foreach (var subPath in fileSystem.EnumeratePaths(path, searchPattern, searchOption, searchTarget)) { yield return(fileSystem.DirectoryExists(subPath) ? (ReadOnlyFileSystemEntry) new ReadOnlyDirectoryEntry(fileSystem, subPath) : new ReadOnlyFileEntry(fileSystem, subPath)); } }
/// <summary> /// Returns an enumerable collection of file names in a specified path. /// </summary> /// <param name="fileSystem">The file system.</param> /// <param name="path">The path of the directory to look for files.</param> /// <param name="searchPattern">The search string to match against the names of directories in path. This parameter can contain a combination /// of valid literal path and wildcard (* and ?) characters (see Remarks), but doesn't support regular expressions.</param> /// <param name="searchOption">One of the enumeration values that specifies whether the search operation should include only the current directory /// or should include all subdirectories. /// The default value is TopDirectoryOnly.</param> /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns> public static IEnumerable <UPath> EnumerateFiles(this IReadOnlyFileSystem fileSystem, UPath path, string searchPattern, SearchOption searchOption) { if (searchPattern == null) { throw new ArgumentNullException(nameof(searchPattern)); } foreach (var subPath in fileSystem.EnumeratePaths(path, searchPattern, searchOption, SearchTarget.File)) { yield return(subPath); } }