Skip to content

Commit a6f0bad

Browse files
authored
(#203) Add PathIo.EnumerateFiles extensions
1 parent 5d73f39 commit a6f0bad

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

TruePath.SystemIo/PathIo.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,4 +771,55 @@ public static class PathIo
771771
/// <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.</param>
772772
/// <returns>An array of the full names (including paths) for the subdirectories in the specified directory that match the specified search pattern and option.</returns>
773773
public static string[] GetDirectories(this AbsolutePath path, string searchPattern, SearchOption searchOption) => Directory.GetDirectories(path.Value, searchPattern, searchOption);
774+
775+
/// <summary>
776+
/// Returns an enumerable collection of <see cref="AbsolutePath"/> of full file names in a specified path.
777+
/// </summary>
778+
/// <param name="path">The directory to search.</param>
779+
/// <returns>An enumerable collection of <see cref="AbsolutePath"/> of the full names (including paths) for the files in the specified directory that match the specified search pattern.</returns>
780+
public static IEnumerable<AbsolutePath> EnumerateFiles(this AbsolutePath path)
781+
{
782+
return Directory.EnumerateFiles(path.Value)
783+
.Select(filename => path / filename);
784+
}
785+
786+
/// <summary>
787+
/// Returns an enumerable collection of <see cref="AbsolutePath"/> of full file names in a specified path.
788+
/// </summary>
789+
/// <param name="path">The directory to search.</param>
790+
/// <param name="searchPattern">The search string to match against the names of files in <paramref name="path"/>.</param>
791+
/// <returns>An enumerable collection of <see cref="AbsolutePath"/> of the full names (including paths) for the files in the specified directory that match the specified search pattern.</returns>
792+
public static IEnumerable<AbsolutePath> EnumerateFiles(this AbsolutePath path, string searchPattern)
793+
{
794+
return Directory.EnumerateFiles(path.Value, searchPattern)
795+
.Select(filename => path / filename);
796+
}
797+
798+
#if NET8_0_OR_GREATER
799+
/// <summary>
800+
/// Returns an enumerable collection of <see cref="AbsolutePath"/> of the names of files (including their paths) that match the specified search pattern and enumeration options in the specified directory.
801+
/// </summary>
802+
/// <param name="path">The directory to search.</param>
803+
/// <param name="searchPattern">The search string to match against the names of files in <paramref name="path"/>.</param>
804+
/// <param name="enumerationOptions">An object that contains the search options to use.</param>
805+
/// <returns>An enumerable collection of <see cref="AbsolutePath"/> of the full names (including paths) for the files in the specified directory that match the specified search pattern and enumeration options.</returns>
806+
public static IEnumerable<AbsolutePath> EnumerateFiles(this AbsolutePath path, string searchPattern, EnumerationOptions enumerationOptions)
807+
{
808+
return Directory.EnumerateFiles(path.Value, searchPattern, enumerationOptions)
809+
.Select(filename => path / filename);
810+
}
811+
#endif
812+
813+
/// <summary>
814+
/// Returns an enumerable collection of <see cref="AbsolutePath"/> with the names of files (including their paths) that match the specified search pattern in the specified directory, using a value to determine whether to search subdirectories.
815+
/// </summary>
816+
/// <param name="path">The directory to search.</param>
817+
/// <param name="searchPattern">The search string to match against the names of files in <paramref name="path"/>.</param>
818+
/// <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.</param>
819+
/// <returns>An enumerable collection of <see cref="AbsolutePath"/> of the full names (including paths) for the files in the specified directory that match the specified search pattern.</returns>
820+
public static IEnumerable<AbsolutePath> EnumerateFiles(this AbsolutePath path, string searchPattern, SearchOption searchOption)
821+
{
822+
return Directory.EnumerateFiles(path.Value, searchPattern, searchOption)
823+
.Select(filename => path / filename);
824+
}
774825
}

0 commit comments

Comments
 (0)