glob
File glob pattern matching - match a path string against a glob pattern supporting * (any chars in segment), ? (any single char), [chars] and [!chars] character classes, and **/ (recursive any-depth prefix). Filter lists of paths, match against multiple patterns, and use built-in common patterns.
Load with: use glob
What this module does
glob provides shell-style glob matching without touching the filesystem.
Pass any string path to globm with a pattern like "**/*.ilu"
or "src/[abc]*.txt" and get back tru or fls.
Patterns with a **/ prefix are handled specially: the remainder of the
pattern is tried at every path depth. All other patterns use a single-pass
backtracking matcher that handles *, ?, and character classes.
Quick example
use glob
# Single-pattern match
prn(globm("**/*.ilu", "src/lib/util.ilu")) # tru
prn(globm("*.txt", "readme.md")) # fls
prn(globm("src/[abc]*.ilu", "src/app.ilu")) # tru
prn(globm("src/[!x]*.ilu", "src/app.ilu")) # tru
# Filter a list
files = ["a.ilu", "b.txt", "c.ilu"]
prn(globf(files, "*.ilu")) # ["a.ilu", "c.ilu"]
# Match any of multiple patterns
prn(globa("app.ilu", ["*.ilu", "*.txt"])) # tru
# Built-in patterns
prn(globi()) # "**/*.ilu" - all ilusm files
prn(globe("html")) # "*.html"
Functions
Matching
globm(pattern, path)
Matches path against pattern. If the pattern starts with **/, tries the remainder of the pattern at every path depth. Otherwise uses the single-segment pattern matcher.
globp(pattern, string)
Core pattern matcher. Supports * (zero or more chars), ? (exactly one char), and [chars] / [!chars] character classes. Uses backtracking on * to find the longest match.
globn(pattern)
Returns tru if the pattern is negated (starts with !). Useful for implementing .gitignore-style exclusion rules.
Filtering and multi-pattern
globf(paths, pattern)
Filters a list of path strings, returning only those that match pattern via globm.
globa(path, patterns)
Returns tru if path matches any pattern in the patterns list.
Built-in patterns
globa()
Returns "**/*" - matches all files at any depth.
globe(ext)
Returns "*.{ext}" - matches all files with a given extension in the current directory.
globi()
Returns "**/*.ilu" - matches all ilusm source files recursively.
Notes
- Matching is purely string-based -
globdoes not read the filesystem. Combine withfs.lsorfs.findto find actual files. - Requires
trlandtxt.