Documentation
¶
Overview ¶
Package glob provides utilities for matching patterns against filesystem trees.
The matcher is designed to read as few directories as possible while matching; only directories that may contain matches are considered.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Glob ¶
type Glob interface {
// Match returns a sequence of (string, error) pairs for paths under dir that match the glob's include and exclude
// patterns. The error portion of a pair is only non-nil when the path portion is a directory and Match fails to
// read the directory's entries. If includeDirs is true, matching directories will be included in the sequence prior
// to their contents.
Match(fsys fs.FS, dir string, includeDirs bool) iter.Seq2[string, error]
// MatchPath returns true if the given path matches the glob's includes and excludes.
MatchPath(path string) bool
}
A Glob matches paths in a directory against a set of include and exclude patterns.
func New ¶
New creates a new Glob from the given lists of include and exclude patterns.
A Glob matches a particular path p if any of its include patterns matches p and none of its exclude patterns match p.
The pattern syntax is:
pattern:
pathTerm { '/' pathTerm }
pathTerm:
'**' matches any sequence of directory names, including the empty sequence
{ term } matches a sequence of terms against a name
term:
'*' matches any sequence of non-/ characters
'?' matches any single non-/ character
'[' [ '^' ] { character-range } ']'
character class (must be non-empty)
c matches character c (c != '*', '?', '\\', '[')
'\\' c matches character c
character-range:
c matches character c (c != '\\', '-', ']')
'\\' c matches character c
lo '-' hi matches character c for lo <= c <= hi
Patterns require that path terms match all of name, not just a substring. If any error is returned, it will be a list of path.ErrBadPattern errors.