Need help with glob?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

kthompson
160 Stars 20 Forks MIT License 97 Commits 3 Opened issues

Description

A C# Glob library for .NET and .NET Core.

Services available

!
?

Need anything else?

Contributors list

# 272,993
Scala
intelli...
scalaz
c-sharp
84 commits
# 470,062
C
Shell
c-sharp
.NET
2 commits
# 401,787
Shell
F#
dotnet-...
.NET
1 commit
# 119,648
asp-net...
c-sharp
WPF
WinForm...
1 commit
# 288,215
unittes...
.NET
entity-...
entity-...
1 commit
# 3,242
imagema...
sass-fr...
splash
pipelin...
1 commit
# 110,610
c-sharp
REST AP...
mariadb
MySQL
1 commit
# 14,366
C#
mahapps
WPF
c-sharp
1 commit

Glob

Join the chat at https://gitter.im/kthompson/glob Build status Coverage Tests Nuget

A C# Glob library for .NET and .NET Core.

What is a glob?

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.

Try it out!

You can test out Glob expressions using this library in your browser by visiting:

https://kthompson.github.io/glob/

image

Supported Environments

  • Windows
  • Macintosh OS X (Darwin)
  • Linux

Features

Common Expressions

| 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
|

Expressions

| 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' |

Other Features

  • Escape patterns are supported using
    \
  • Pure C# implementation
  • No reliance on Regex
  • Simple text string matching support
  • File system matching APIs

Usage

Example

var glob = new Glob("**/bin");
var match = glob.IsMatch(@"C:\files\bin\");

Static Usage

Single file

var match = Glob.IsMatch(@"C:\files\bin\", "**/bin");   

Files in a directory

string[] matchingFiles = Glob.Files(@"C:\files\bin\", "**/bin").ToArray();  

Directories in a directory

string[] matchingDirectories = Glob.Directories(@"C:\files\bin\", "**/bin").ToArray();  

Extension Methods

DirectoryInfo.GlobDirectories

Enumerate through all matching directories recursively.

Params

  • pattern: String

Example

var root = new DirectoryInfo(@"C:\");
var allBinFolders = root.GlobDirectories("**/bin");

DirectoryInfo.GlobFiles

Enumerate through all matching files recursively.

Params

  • pattern: String

Example

var root = new DirectoryInfo(@"C:\");
var allDllFiles = root.GlobFiles("**/*.dll");

DirectoryInfo.GlobFileSystemInfos

Enumerate through all matching files and folders recursively.

Params

  • pattern: String

Example

var root = new DirectoryInfo(@"C:\");
var allInfoFilesAndFolders = root.GlobFileSystemInfos("**/*info");

Upgrading from 1.x

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.

Performance

See benchmarks

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.