Skip to content

Commit

Permalink
Merge pull request #7 from rameel/traversal
Browse files Browse the repository at this point in the history
Implement file and directory enumeration
  • Loading branch information
rameel authored Jul 15, 2024
2 parents 8c33d84 + fdfb37b commit ab5233a
Show file tree
Hide file tree
Showing 4 changed files with 590 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
</PropertyGroup>
</Project>
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,39 @@ We use optimizations that prevent quadratic behavior in scenarios like the patte
matching against the text `aaaaaaaaaaaaaaa...aaaa...aaa`.
Similarly, for the `a/**/a/**/a/**/.../a/**/a/**/a/**/b` pattern matching against `a/a/a/a/.../a/.../a`.

## File traversal

The `Files` class provides functionality for traversing the file system and retrieving lists of files and directories based on specified glob patterns. This allows for flexible and efficient file and directory enumeration.

```csharp
using Ramstack.Globbing.Traversal;

// List all *.cs files
var files = Files.EnumerateFiles(@"/path/to/directory", "**/*.cs");
foreach (var file in files)
Console.WriteLine(file);

// List all *.cs files except in tests directory
var files = Files.EnumerateFiles(@"/path/to/directory", "**/*.cs", "tests");
foreach (var file in files)
Console.WriteLine(file);
```
Support for multiple patterns is also included:

```csharp
using Ramstack.Globbing.Traversal;

// List all *.cs files
var files = Files.EnumerateFiles(@"/path/to/directory", ["src/**/*.cs", "lib/**/*.cs"], ["**/tests"]);
foreach (var file in files)
Console.WriteLine(file);
```

## Changelog

### 2.0.0
* Added the ability to retrieve a list of files and directories based on a specified glob pattern.

**BREAKING CHANGE**

To improve code readability and adherence to .NET conventions, the order of parameters in the `IsMatch` method has been changed.
Expand Down
53 changes: 47 additions & 6 deletions Ramstack.Globbing/Matcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,54 @@ namespace Ramstack.Globbing;

/// <summary>
/// Provides functionality for shell-style glob matching using the glob pattern syntax.
/// <para>Supported meta-characters include '*', '?', '\' and '[', ']'. And inside character classes '-', '!' and ']'.</para>
/// <para>The '.' and '..' symbols do not have any special treatment and are processed as regular characters for matching.</para>
/// <para>Character classes can be negated by prefixing them with '!', such as [!0-9], which matches all characters except digits.</para>
/// <para>Brace patterns are supported, including nested brace pattern: {file,dir,name}, {file-1.{c,cpp},file-2.{cs,f}}</para>
/// <para>An empty pattern in brace expansion {} is allowed, as well as variations like {.cs,}, {name,,file}, or {,.cs}.</para>
/// <para>Leading and trailing separators are ignored, and consecutive delimiters are counted as one.</para>
/// </summary>
/// <remarks>
/// <list type="bullet">
/// <item>
/// <description>
/// Supported meta-characters include <c>'*'</c>, <c>'?'</c>, <c>'\'</c> and <c>'['</c>, <c>']'</c>.
/// And inside character classes <c>'-'</c>, <c>'!'</c> and <c>']'</c>.
/// </description>
/// </item>
/// <item>
/// <description>
/// The <c>'.'</c> and <c>'..'</c> symbols do not have any special treatment and are processed
/// as regular characters for matching.
/// </description>
/// </item>
/// <item>
/// <description>
/// Character classes can be negated by prefixing them with <c>'!'</c>, such as <c>[!0-9]</c>,
/// which matches all characters except digits.
/// </description>
/// </item>
/// <item>
/// <description>
/// Brace patterns are supported, including nested brace pattern:
/// <c>{file,dir,name}</c>, <c>{file-1.{c,cpp},file-2.{cs,f}}</c>
/// </description>
/// </item>
/// <item>
/// <description>
/// An empty pattern in brace expansion <c>{}</c> is allowed, as well as variations
/// like <c>{.cs,}</c>, <c>{name,,file}</c>, or <c>{,.cs}</c>.
/// </description>
/// </item>
/// <item>
/// <description>Leading and trailing separators are ignored.</description>
/// </item>
/// <item>
/// <description>Consecutive separators are counted as one.</description>
/// </item>
/// <item>
/// <description>
/// The <c>'**'</c> sequence in the glob pattern can be used to match zero or more directories and subdirectories.
/// It can be used at the beginning, middle, or end of a pattern, for example,
/// <c>"**/file.txt"</c>, <c>"dir/**/*.txt"</c>, <c>"dir/**"</c>.
/// </description>
/// </item>
/// </list>
/// </remarks>
public static unsafe class Matcher
{
/// <summary>
Expand Down
Loading

0 comments on commit ab5233a

Please sign in to comment.