Golang globs and the Double Star Glob Operator
Golang's glob library doesn't support the ** double-star or globstar operator. Here's how to get it.
The golang filepath/glob and filepath/match functions provide glob matching but does not support the "double star", "double asterisk", "globstar", "super glob", "super wildcard" operation that descends into other directories. According to Issue 11862 the problem seems to be handling edge cases like crossing file system boundaries, symlinks and infinite loops (if I read @rsc's comment correctly).
In the meantime, one of these packages might work:
- mattn/go-zglob looks very optimized for filewalking
- bmatcuk/doublestar appears to be the most mature
- godo/glob.go is an implementation embedded inside godo
In addition gobwas/glob is an excellent generic glob package that claims huge performance advantages over other globs and the equivalent regular expressions. It does not however provide a filewalker.
Happy globbing, and if you want to know more about the science of globs, @rsc wrote it up for you.
Notes
- In bash 4, you can turn on globstar with
shopt -s globstar
- The latest macOS (
10.12.410.13.3) uses a very old bash 3 and doesn't support globstar. - Java's FileSystem#getPathMatcher describes globstar in more detail.