dennisdoomen / dennisdoomen/pathy

[API Proposal]: Children, Files and Directories enumeration without the globbing package

Open
#137 0 comments 0 reactions 0 assignees View on GitHub
breaking enhancement
Dominant language
C#
Stars
27
Forks
5
Avg merge
21h 29m
Merged PRs (30d)
10

Description

### Background and motivation

Listing the contents of a directory currently requires either the separate `Pathy.Globbing` package (and therefore a dependency on `Microsoft.Extensions.FileSystemGlobbing`) or a drop down to `ToDirectoryInfo()`. For the simple, extremely common case of "give me the entries in this directory", neither is appropriate. The core package can offer this with no new dependencies, since it is a thin wrapper over `Directory.Enumerate*`.

### API Proposal

```C#
namespace Pathy
{
public static class ChainablePathExtensions
{
public static IEnumerable Children(this ChainablePath path, bool recursive = false);
public static IEnumerable Files(this ChainablePath path, bool recursive = false);
public static IEnumerable Directories(this ChainablePath path, bool recursive = false);
}
}
```

### API Usage

```C#
foreach (var project in (ChainablePath.Current / "src").Directories())
{
Console.WriteLine(project.Name);
}

var configFiles = (ChainablePath.Current / "config").Files()
.Where(x => x.HasExtension(".json"));

var everything = ChainablePath.Current.Children(recursive: true);
```

### Alternative Designs

* Point people at `Pathy.Globbing` and `GlobFiles("*")`. That forces a package and a transitive dependency on consumers who only wanted to list a folder.
* Expose these as properties. Enumeration hits the file system and can be expensive, so methods communicate the cost better.

### Risks

Behaviour on a path that does not exist, or that points at a file rather than a directory, has to be defined: returning an empty sequence is friendlier than throwing but can hide mistakes. Recursive enumeration also has to state what happens when a subdirectory cannot be accessed.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing ChainablePathExtensions API and the Pathy.Globbing alternative, then compare the proposal with the underlying Directory.Enumerate* behavior. The issue is not ready to implement until behavior for missing paths, file paths, and inaccessible recursive entries is decided; done would include the three methods and settled semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.