(glob "/usr/man/man?/") ==> 
        ("/usr/man/man1/" "/usr/man/man2/" ...)

Globbing can sometimes be useful when we need a list of a directory's files where each element in the list includes the pathname for the file. Compare:


(directory-files "../include") ==> 
    ("cig.h" "decls.h" ...)

(glob "../include/*") ==> 
    ("../include/cig.h" "../include/decls.h" ...)

(glob-quote str)     →     string         (procedure) 
Returns a constant glob pattern that exactly matches str. All wild-card characters in str are quoted with a backslash.

(glob-quote "Any *.c files?")
    ==> "Any \*.c files\?"

(glob pat1 ...)     →     string list         (procedure) 
Glob each pattern against the filesystem and return the sorted list. Duplicates are not removed. Patterns matching nothing are not included literally, as they are in the shell. Shell {a,b,c} patterns are expanded. Backslash quotes characters, turning off the special meaning of {, }, *, [, ], and ?.

Note that the rules of backslash for Scheme strings and glob patterns work together to require four backslashes in a row to specify a single literal backslash. Fortunately, it is very rare that a backslash occurs in a POSIX file name.

A glob subpattern will not match against dot files unless the first character of the subpattern is a literal ".". Further, a dot subpattern will not match the files . or .. unless it is a constant pattern, as in (glob "../*/*.c"). So a directory's dot files can be reliably generated with the simple glob pattern ".*".

Some examples:

(glob "*.c" "*.h")
    ;; All the C and #include files in my directory.

(glob "*.c" "*/*.c")
    ;; All the C files in this directory and
    ;; its immediate subdirectories.

(glob "lexer/*.c" "parser/*.c")
(glob "{lexer,parser}/*.c")
    ;; All the C files in the lexer and parser dirs.

(glob "\\{lexer,parser\\}/*.c")
    ;; All the C files in the strange
    ;; directory "{lexer,parser}".

(glob "*\\*")
    ;; All the files ending in "*", e.g.
    ;; ("foo*" "bar*")

(glob "*lexer*")
    ("mylexer.c" "lexer1.notes")
    ;; All files whose names contain the string "lexer".

(glob "lexer")
    ;; Either ("lexer") or ().

If the first character of the pattern (after expanding braces) is a slash, the search begins at root; otherwise, the search begins in the current working directory.

If the last character of the pattern (after expanding braces) is a slash, then the result matches must be directories, e.g.,