Commit b99a34bc authored by Eli Zaretskii's avatar Eli Zaretskii
Browse files

Document 'directory-files-recursively'

* lisp/files.el (directory-files-recursively): Doc fix.  Rename
the argument MATCH to REGEXP, to be more explicit about its form.

* doc/lispref/files.texi (Contents of Directories): Improve the
documentation of 'directory-files-recursively'.  Add
cross-references.

* etc/NEWS: Move the entry for 'directory-files-recursively' to
its place and mark it documented.
parent e702ab8d
......@@ -2632,12 +2632,20 @@ An error is signaled if @var{directory} is not the name of a directory
that can be read.
@end defun
@defun directory-files-recursively directory match &optional include-directories
Return all files under @var{directory} whose file names match
@var{match} recursively. The file names are returned depth first,
meaning that contents of sub-directories are returned before contents
of the directories. If @var{include-directories} is non-@code{nil},
also return directory names that have matching names.
@defun directory-files-recursively directory regexp &optional include-directories
Return all files under @var{directory} whose names match @var{regexp}.
This function searches the specified @var{directory} and its
sub-directories, recursively, for files whose basenames (i.e., without
the leading directories) match the specified @var{regexp}, and returns
a list of the absolute file names of the matching files
(@pxref{Relative File Names, absolute file names}). The file names
are returned in depth-first order, meaning that files in some
sub-directory are returned before the files in its parent directory.
In addition, matching files found in each subdirectory are sorted
alphabetically by their basenames. By default, directories whose
names match @var{regexp} are omitted from the list, but if the
optional argument @var{include-directories} is non-@code{nil}, they
are included.
@end defun
@defun directory-files-and-attributes directory &optional full-name match-regexp nosort id-format
......
......@@ -181,9 +181,6 @@ for use in Emacs bug reports.
hiding character but the default `.' can be used by let-binding the
variable `read-hide-char'.
** A new function `directory-files-recursively' returns all matching
files (recursively) under a directory.
** The new function `directory-name-p' can be used to check whether a file
name (as returned from, for instance, `file-name-all-completions' is
a directory file name. It returns non-nil if the last character in
......@@ -1137,6 +1134,10 @@ of subprocess.
process filter, sentinel, etc., through keyword arguments (similar to
`make-network-process').
+++
** A new function `directory-files-recursively' returns all matching
files (recursively) under a directory.
+++
** New variable `inhibit-message', when bound to non-nil, inhibits
`message' and related functions from displaying messages the Echo
......
......@@ -744,11 +744,13 @@ The path separator is colon in GNU and GNU-like systems."
(and (> (length name) 0)
(char-equal (aref name (1- (length name))) ?/)))
(defun directory-files-recursively (dir match &optional include-directories)
"Return all files under DIR that have file names matching MATCH (a regexp).
(defun directory-files-recursively (dir regexp &optional include-directories)
"Return list of all files under DIR that have file names matching REGEXP.
This function works recursively. Files are returned in \"depth first\"
and alphabetical order.
If INCLUDE-DIRECTORIES, also include directories that have matching names."
order, and files from each directory are sorted in alphabetical order.
Each file name appears in the returned list in its absolute form.
Optional argument INCLUDE-DIRECTORIES non-nil means also include in the
output directories whose names match REGEXP."
(let ((result nil)
(files nil)
;; When DIR is "/", remote file names like "/method:" could
......@@ -764,11 +766,11 @@ If INCLUDE-DIRECTORIES, also include directories that have matching names."
(unless (file-symlink-p full-file)
(setq result
(nconc result (directory-files-recursively
full-file match include-directories))))
full-file regexp include-directories))))
(when (and include-directories
(string-match match leaf))
(string-match regexp leaf))
(setq result (nconc result (list full-file)))))
(when (string-match match file)
(when (string-match regexp file)
(push (expand-file-name file dir) files)))))
(nconc result (nreverse files))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment