The Wayback Machine - https://web.archive.org/web/20201026174625/https://github.com/kthompson/glob
Skip to content
master
Go to file
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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.

Supported Environments

  • Windows
  • Macintosh OS X (Darwin)
  • Linux

Supported Pattern expressions

Pattern Description
* matches any number of characters including none, excluding directory seperator
? 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'

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");

Performance

See benchmarks

You can’t perform that action at this time.