diff --git a/CHANGELOG.md b/CHANGELOG.md
index 73f67ce..7fd0bba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- `LocalPath.PathRoot`, returning the root of an absolute path, or the drive root of a drive-relative path (e.g. `C:foo`, which only exists on Windows), or `null` when the root can't be determined.
- `AbsolutePath.PathRoot` property.
- [#224](https://github.com/ForNeVeR/TruePath/issues/224): `PathKind` enumeration and `LocalPath.Kind` property, telling an absolute path from a relative one, and on Windows also from a path rooted without a drive letter (`\Windows`) and from a path relative to the current directory of a drive (`C:Windows`). These are **experimental** (diagnostic `TRUEPATH001`): more kinds may be added later, e.g. for UNC paths.
+- [#202: `path.GetFiles(LocalPathPattern)`](https://github.com/ForNeVeR/TruePath/issues/202).
### Changed
- **Breaking:** on Windows, `LocalPath.IsAbsolute` now only returns `true` for fully qualified paths, such as `C:\Windows`. Paths rooted without a drive letter (`\Windows`), and paths relative to the current directory of a drive (`C:Windows`, `C:`) are not absolute anymore, and `AbsolutePath` now rejects them. Previously, this was following the `Path.IsPathRooted` API.
diff --git a/TruePath.SystemIo/PathIo.cs b/TruePath.SystemIo/PathIo.cs
index 9844a79..338e675 100644
--- a/TruePath.SystemIo/PathIo.cs
+++ b/TruePath.SystemIo/PathIo.cs
@@ -743,6 +743,18 @@ public static class PathIo
/// An array of the full names (including paths) for the files in the specified directory that match the specified search pattern.
public static string[] GetFiles(this AbsolutePath path, string searchPattern) => Directory.GetFiles(path.Value, searchPattern);
+ ///
+ /// Returns the names of files (including their paths) that match the specified search pattern in the specified directory.
+ ///
+ /// The directory to search.
+ /// The search pattern to match against the names of files in .
+ ///
+ /// An array of the absolute paths for the files in the specified directory that match the specified search
+ /// pattern.
+ ///
+ public static AbsolutePath[] GetFiles(this AbsolutePath path, LocalPathPattern searchPattern) =>
+ Directory.GetFiles(path.Value, searchPattern.Value).Select(x => new AbsolutePath(x)).ToArray();
+
#if NET8_0_OR_GREATER
///
/// Returns the names of files (including their paths) that match the specified search pattern and enumeration options in the specified directory.
diff --git a/TruePath.Tests/PathIoTests.cs b/TruePath.Tests/PathIoTests.cs
index d581fa8..9837266 100644
--- a/TruePath.Tests/PathIoTests.cs
+++ b/TruePath.Tests/PathIoTests.cs
@@ -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], files);
+ });
+ }
+
private static void DoWithTempFolder(Action test)
{
var tempFolder = Temporary.CreateTempFolder();