A C# Glob library for .NET.
A glob is a pattern-matching syntax that shells use. Like when you do
rm *.cs, the *.cs is a glob.
See: http://en.wikipedia.org/wiki/Glob_(programming) for more info.
You can test out Glob expressions using this library in your browser by visiting:
https://kthompson.github.io/glob/
- Windows
- Macintosh OS X (Darwin)
- Linux
| Pattern | Description |
|---|---|
| taco* | matches any string beginning with taco |
| *taco* | matches any string containing taco |
| *taco | matches any string ending in taco |
| *.[ch] | matches any string ending in .c or .h |
| *.{gif,jpg} | match any string ending in .gif or .jpg |
| Pattern | Description |
|---|---|
| * | matches any number of characters including none, excluding directory separator |
| ? | matches a single character |
| [abc] | matches one character in the brackets |
| [!abc] | matches any character not in the brackets |
| ** | match zero or more directories |
| {abc,123} | comma delimited set of literals, matched 'abc' or '123' |
- Escape patterns are supported using
\ - Pure C# implementation
- No reliance on Regex
- Simple text string matching support
- File system matching APIs
dotnet add package GlobTo use Glob, you need to include the namespace:
using GlobExpressions;var glob = new Glob("**/bin");
var match = glob.IsMatch(@"C:\files\bin\");var match = Glob.IsMatch(@"C:\files\bin\", "**/bin"); string[] matchingFiles = Glob.Files(@"C:\files\bin\", "**/bin").ToArray(); string[] matchingDirectories = Glob.Directories(@"C:\files\bin\", "**/bin").ToArray(); Enumerate through all matching directories recursively.
- pattern: String
var root = new DirectoryInfo(@"C:\");
var allBinFolders = root.GlobDirectories("**/bin");Enumerate through all matching files recursively.
- pattern: String
var root = new DirectoryInfo(@"C:\");
var allDllFiles = root.GlobFiles("**/*.dll");Enumerate through all matching files and folders recursively.
- pattern: String
var root = new DirectoryInfo(@"C:\");
var allInfoFilesAndFolders = root.GlobFileSystemInfos("**/*info");In 2.x all Glob expressions no longer support \ as path separators. Instead / should be used to separate paths in expressions.
The / path separator will still match on platform specific directory separators but \ is reserved for escape sequences.
