Glob: Unix-Style globbing in Racket
(require glob) | package: glob |
A glob is like a path string, but allows wildcard characters. This library brings Unix-style globbing to Racket.
Typed Racket users should (require glob/typed) for a type-annotated API.You may use glob in a typed module via require/typed; however, bindings from glob/typed may not be used in untyped code.
1 API Functions
procedure
(glob glob-string [ #:with-dotfiles? dotfiles?]) → (listof path-string) glob-string : string dotfiles? : boolean = #f
> (glob "*.scrbl") '()
> (glob "glob*") '()
> (glob "*.rkt") '("./info.rkt" "./main.rkt" "./typed.rkt")
procedure
(in-glob glob-string [ #:with-dotfiles? dotfiles?]) → (sequenceof path-string) glob-string : string dotfiles? : boolean = #f
> (let ([tmp (path->string (find-system-path 'temp-dir))]) (sequence-length (in-glob (string-append tmp "/*")))) 0
> (let ([tmp (path->string (find-system-path 'temp-dir))]) (sequence-length (in-glob (string-append tmp "/*") #:with-dotfiles? #t))) 0
The matches returned by either function should be exactly the same as those returned by the Unix glob file \. -name glob-path-string. Please submit an issue if you find a counterexample.
2 Typed API
(require glob/typed) | package: glob |
3 Globbing 101
Globs are path strings that may contain the following special characters.
* is a wildcard. It means "match anything". For example, (glob "*.rkt") will match all files in the current directory with a .rkt file extension.
? is an option. It means "the previous character might not be there". For example, (glob "*.rktd?") will match all .rkt and all .rktd files in the current directory.
Square braces [] are for branching on single characters. The pattern [abc] means "match ’a’, or match ’b’, or match ’c’". For example, (glob "*.[co]") will match all .c and all .o files in the current directory.
4 Credits
Inspired by the Python glob library.