Next: , Previous: Getopt Parameter lists, Up: Programs and Arguments

4.4.6 Filenames

(require 'filename)

— Function: filename:match?? pattern
— Function: filename:match-ci?? pattern

Returns a predicate which returns a non-false value if its string argument matches (the string) pattern, false otherwise. Filename matching is like glob expansion described the bash manpage, except that names beginning with ‘.’ are matched and ‘/’ characters are not treated specially.

These functions interpret the following characters specially in pattern strings:

Matches any string, including the null string.
Matches any single character.
Matches any one of the enclosed characters. A pair of characters separated by a minus sign (-) denotes a range; any character lexically between those two characters, inclusive, is matched. If the first character following the ‘[’ is a ‘!’ or a ‘^’ then any character not enclosed is matched. A ‘-’ or ‘]’ may be matched by including it as the first or last character in the set.

— Function: filename:substitute?? pattern template
— Function: filename:substitute-ci?? pattern template

Returns a function transforming a single string argument according to glob patterns pattern and template. pattern and template must have the same number of wildcard specifications, which need not be identical. pattern and template may have a different number of literal sections. If an argument to the function matches pattern in the sense of filename:match?? then it returns a copy of template in which each wildcard specification is replaced by the part of the argument matched by the corresponding wildcard specification in pattern. A * wildcard matches the longest leftmost string possible. If the argument does not match pattern then false is returned.

template may be a function accepting the same number of string arguments as there are wildcard specifications in pattern. In the case of a match the result of applying template to a list of the substrings matched by wildcard specifications will be returned, otherwise template will not be called and #f will be returned.

     ((filename:substitute?? "scm_[0-9]*.html" "scm5c4_??.htm")
     ⇒ "scm5c4_10.htm"
     ((filename:substitute?? "??" "beg?mid?end") "AZ")
     ⇒ "begAmidZend"
     ((filename:substitute?? "*na*" "?NA?") "banana")
     ⇒ "banaNA"
     ((filename:substitute?? "?*?" (lambda (s1 s2 s3) (string-append s3 s1)))
     ⇒ "ZA"
— Function: replace-suffix str old new

str can be a string or a list of strings. Returns a new string (or strings) similar to str but with the suffix string old removed and the suffix string new appended. If the end of str does not match old, an error is signaled.

     (replace-suffix "/usr/local/lib/slib/batch.scm" ".scm" ".c")
     ⇒ "/usr/local/lib/slib/batch.c"
— Function: call-with-tmpnam proc k
— Function: call-with-tmpnam proc

Calls proc with k arguments, strings returned by successive calls to tmpnam. If proc returns, then any files named by the arguments to proc are deleted automatically and the value(s) yielded by the proc is(are) returned. k may be ommited, in which case it defaults to 1.

— Function: call-with-tmpnam proc suffix1 ...

Calls proc with strings returned by successive calls to tmpnam, each with the corresponding suffix string appended. If proc returns, then any files named by the arguments to proc are deleted automatically and the value(s) yielded by the proc is(are) returned.