.NET Fiddle

CSharp · Console

/Program.cs

using System;
using System.IO;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;

string rootPath = "/tmp/root";
string excludeMePath = Path.Combine(rootPath, "ExcludeMe");
string includeMePath = Path.Combine(excludeMePath, "ButActuallyIncludeMe");

Directory.CreateDirectory(rootPath);
Directory.CreateDirectory(excludeMePath);
Directory.CreateDirectory(includeMePath);

File.WriteAllText(Path.Combine(rootPath, "helloWorld.txt"), "Hello, World!");
File.WriteAllText(Path.Combine(excludeMePath, "notIncluded.txt"), "Not included");
File.WriteAllText(Path.Combine(includeMePath, "hiEarth.txt"), "Hi, Earth!");

var matcher = new Matcher();

matcher.AddInclude("**/*"); // Include all files
matcher.AddExclude("ExcludeMe/**/*"); // Exclude everything in the ExcludeMe directory
matcher.AddInclude("ExcludeMe/ButActuallyIncludeMe/**/*"); // Include everything in ButActuallyIncludeMe

var result = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(rootPath)));

Console.WriteLine("Matched Files:");
foreach (var file in result.Files)
{
    Console.WriteLine(file.Path);
}

Directory.Delete(rootPath, true);
;