Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions TruePath.SystemIo/PathIo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,18 @@ 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 absolute paths for the files in the specified directory that match the specified search
/// pattern.
/// </returns>
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
/// <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], files);
});
}

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