Golang globs and the ** Double Star Glob Operator

Nick Galbreath

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 decends into other directories. According to Issue 11862 the problem seems to be handling edge cases like crossing file system boundries, symlinks and infinite loops (if I read rsc’s comment correctly).

In the meantime, one of these packages might work:

In addition gobwas/glob is an excellent generic glob package that claims huge performance advantage 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 sciences of globs, @rsc wrote it up for you.