15 Globbing
A sextile (*) matches any sequence of characters in a file or directory name.
Two sextiles (**) match any sequence of characters and any number of path separators.
A question mark (?) matches any single character in a file or directory name.
Square bracket-delimited character groups, e.g. [abc], match any character within the group. The square brackets have the same meaning in globs as in regular expressions, see Regexp Syntax.
If the glob ends with a path separator (/ on any (system-type), additionally \ on 'windows) then it only matches directories.
On Windows, wildcards cannot be escaped because \ is a path separator.
value
Braces are interpreted before any other wildcards.
Brace-delimited, comma-separated character groups, e.g. {foo,bar}, expand to multiple globs before the file/glob module begins matching. For example, the glob/c value "{foo,bar}.rkt" has the same meaning as '("foo.rkt" "bar.rkt").
procedure
(glob pattern [ #:capture-dotfiles? capture-dotfiles?]) → (listof path-string?) pattern : glob/c capture-dotfiles? : boolean? = (glob-capture-dotfiles?)
If pattern contains the wildcard **, then glob recursively searches the filesystem to find matches. For example, the glob "/**.rkt" will search the entire filesystem for files or directories with a ".rkt" suffix (aka, Racket files).
> (glob "*.rkt") ;; Lists all Racket files in current directory > (glob "*/*.rkt") ;; Lists all Racket files in all sub-directories of the current directory. ;; (Does not search sub-sub-directories, etc.) > (glob (build-path (find-system-path 'home-dir) "**" "*.rkt")) ;; Recursively searches home directory for Racket files, lists all matches. > (glob "??.rkt") ;; Lists all Racket files in current directory with 2-character names. > (glob "[a-z0-9].rkt") ;; Lists all Racket files in current directory with single-character, ;; alphanumeric names. > (glob '("foo-bar.rkt" "foo-baz.rkt" "qux-bar.rkt" "qux-baz.rkt")) ;; Filters the list to contain only files or directories that exist. > (glob "{foo,qux}-{bar,baz}.rkt") ;; Same as above, returns at most 4 files.
procedure
(in-glob pattern [ #:capture-dotfiles? capture-dotfiles?]) → (sequence/c path-string?) pattern : glob/c capture-dotfiles? : boolean? = (glob-capture-dotfiles?)
procedure
(glob-match? pattern path [ #:capture-dotfiles? capture-dotfiles?]) → boolean? pattern : glob/c path : path-string? capture-dotfiles? : boolean? = (glob-capture-dotfiles?)
This operation accesses the filesystem.
procedure
(glob-quote str) → string?
str : string? (glob-quote path) → path? path : path?
> (glob-quote "*.rkt") "\\*.rkt"
> (glob-quote "[Ff]ile?{zip,tar.gz}") "\\[Ff\\]ile\\?\\{zip\\,tar.gz\\}"
> (glob-quote "]") "\\]"
parameter
(glob-capture-dotfiles? capture-dotfiles?) → void? capture-dotfiles? : boolean?
= #f