Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions TruePath.SystemIo/PathIo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,14 @@ public static class PathIo
/// <returns>An array of the full names (including paths) for the files in the specified directory that match the specified search pattern.</returns>
public static string[] GetFiles(this AbsolutePath path, string searchPattern) => Directory.GetFiles(path.Value, searchPattern);

/// <summary>
/// Returns the names of files (including their paths) that match the specified search pattern in the specified directory.
/// </summary>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">The search pattern to match against the names of files in <paramref name="path"/>.</param>
/// <returns>An array of the full names (including paths) for the files in the specified directory that match the specified search pattern.</returns>
public static string[] GetFiles(this AbsolutePath path, LocalPathPattern searchPattern) => Directory.GetFiles(path.Value, searchPattern.Value);

#if NET8_0_OR_GREATER
/// <summary>
/// Returns the names of files (including their paths) that match the specified search pattern and enumeration options in the specified directory.
Expand Down
15 changes: 15 additions & 0 deletions TruePath.Tests/PathIoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ public void ExistsFolderTest()
});
}

[Fact]
public void GetFilesByLocalPathPatternTest()
{
DoWithTempFolder(tempFolder =>
{
var matchingFile = tempFolder / "matching.txt";
matchingFile.WriteAllText("test");
(tempFolder / "other.log").WriteAllText("test");

var files = tempFolder.GetFiles(new LocalPathPattern("*.txt"));

Assert.Equal([matchingFile.Value], files);
});
}

private static void DoWithTempFolder(Action<AbsolutePath> test)
{
var tempFolder = Temporary.CreateTempFolder();
Expand Down
Loading