returns @code{nil}, if directory @samp{/foo} is empty.
@end defvr
-@defun file-expand-wildcards pattern &optional full
+@defun file-expand-wildcards pattern &optional full regexp
This function expands the wildcard pattern @var{pattern}, returning
a list of file names that match it.
+@var{pattern} is, by default, a ``glob''/wildcard string, e.g.,
+@samp{"/tmp/*.png"} or @samp{"/*/*/foo.png"}, but can also be a
+regular expression if the optional @var{regexp} parameter is non-nil.
+In any case, the matches are applied per sub-directory, so a match
+can't span a parent/sub directory.
+
If @var{pattern} is written as an absolute file name,
the values are absolute also.
:no-eval* (directory-files-and-attributes "/tmp/foo"))
(file-expand-wildcards
:no-eval (file-expand-wildcards "/tmp/*.png")
- :eg-result ("/tmp/foo.png" "/tmp/zot.png"))
+ :eg-result ("/tmp/foo.png" "/tmp/zot.png")
+ :no-eval (file-expand-wildcards "/*/foo.png")
+ :eg-result ("/tmp/foo.png" "/var/foo.png"))
(locate-dominating-file
:no-eval (locate-dominating-file "foo.png" "/tmp/foo/bar/zot")
:eg-result "/tmp/foo.png")
:type 'string
:group 'dired)
-(defun file-expand-wildcards (pattern &optional full)
+(defun file-expand-wildcards (pattern &optional full regexp)
"Expand wildcard pattern PATTERN.
This returns a list of file names that match the pattern.
-Files are sorted in `string<' order.
-If PATTERN is written as an absolute file name,
-the values are absolute also.
+PATTERN is, by default, a \"glob\"/wildcard string, e.g.,
+\"/tmp/*.png\" or \"/*/*/foo.png\", but can also be a regular
+expression if the optional REGEXP parameter is non-nil. In any
+case, the matches are applied per sub-directory, so a match can't
+span a parent/sub directory, which means that a regexp bit can't
+contain the \"/\" character.
+
+The list of files returned are sorted in `string<' order.
+
+If PATTERN is written as an absolute file name, the values are
+absolute also.
If PATTERN is written as a relative file name, it is interpreted
relative to the current default directory, `default-directory'.
(dirs (if (and dirpart
(string-match "[[*?]" (file-local-name dirpart)))
(mapcar 'file-name-as-directory
- (file-expand-wildcards (directory-file-name dirpart)))
+ (file-expand-wildcards
+ (directory-file-name dirpart) nil regexp))
(list dirpart)))
contents)
(dolist (dir dirs)
(file-name-nondirectory name))
name))
(directory-files (or dir ".") full
- (wildcard-to-regexp nondir))))))
+ (if regexp
+ nondir
+ (wildcard-to-regexp nondir)))))))
(setq contents
(nconc
(if (and dir (not full))