Glob:   Unix-Style globbing
1 API Functions
glob
in-glob
glob-match?
2 Typed API
3 Globbing 101
4 Credits
6.12

Glob: Unix-Style globbing

NOTE: This library is deprecated; use file/glob, instead.

 (require glob) package: glob

A glob is a pattern over path strings.

Typed Racket users should (require glob/typed).You can use glob in a typed module via require/typed; however, bindings from glob/typed cannot be used in untyped code.

1 API Functions

procedure

(glob pattern [#:with-dotfiles? dotfiles?])  (listof path-string)

  pattern : string
  dotfiles? : boolean = #f
Builds a list of all paths matching the glob pattern. By default, wildcards ("*") in pattern will not capture files or directories whose name begins with a period (aka "dotfiles"). Setting dotfiles? to #t overrides this behavior.

Examples:
> (glob "*.scrbl")

'()

> (glob "glob*")

'()

> (glob "*.rkt")

'("./info.rkt" "./main.rkt" "./typed.rkt")

procedure

(in-glob pattern    
  [#:with-dotfiles? dotfiles?])  (sequenceof path-string)
  pattern : string
  dotfiles? : boolean = #f
Returns a sequence of all paths matching the glob pattern, instead of building a list. When the keyword argument is #t, wildcards will capture dotfiles.

Examples:
> (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 globbing function should be exactly the same as those returned by the Unix glob file \. -name pattern. Please submit an issue if you find a counterexample.

procedure

(glob-match? pattern path)  boolean

  pattern : string
  path : path-string
Returns the same result as:

(member path (glob pattern))

except that it can be faster. This operation queries the filesystem to ensure that path exists.

2 Typed API

 (require glob/typed) package: glob
Provides a Typed Racket version of the glob API.

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.

Aside from these pattern variables, a glob is just a path-string.

4 Credits

Inspired by the Python glob library.