Glob

The Glob module provides glob pattern matching for files and strings. Glob patterns use wildcards to match file paths and strings.

Pattern Syntax
  • * - matches any sequence of characters (except /)
  • ** - matches any sequence including / (recursive)
  • ? - matches any single character
  • [abc] - matches any character in the set
  • [!abc] - matches any character not in the set

Pattern Matching

Glob.match?
String -> String -> Bool
Tests if a string matches a glob pattern.
println (Glob.match? "*.txt" "readme.txt")
# => true

println (Glob.match? "*.txt" "readme.md")
# => false

println (Glob.match? "test-?.kit" "test-1.kit")
# => true

println (Glob.match? "src/**/*.kit" "src/lib/utils/helper.kit")
# => true

Finding Files

Glob.files
String -> String -> Result (List String) String
Finds all files matching a glob pattern relative to a base directory. Only returns files (not directories).
match Glob.files "." "**/*.kit"
  | Ok files -> files |> each fn(f) => println f
  | Err msg -> println "Error: ${msg}"
# => "src/main.kit"
# => "src/lib/utils.kit"
# => "tests/test-utils.kit"
Glob.all
String -> String -> Result (List String) String
Finds all entries (files and directories) matching a glob pattern.
match Glob.all "." "src/*"
  | Ok entries -> entries |> each fn(e) => println e
  | Err msg -> println "Error: ${msg}"
# => "src/main.kit"
# => "src/lib"
# => "src/utils"