aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/lispref/files.texi20
-rw-r--r--etc/NEWS7
-rw-r--r--lisp/files.el16
3 files changed, 27 insertions, 16 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index 9a1b2cd217f..e8ed7ccd9f7 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -2632,12 +2632,20 @@ An error is signaled if @var{directory} is not the name of a directory
2632that can be read. 2632that can be read.
2633@end defun 2633@end defun
2634 2634
2635@defun directory-files-recursively directory match &optional include-directories 2635@defun directory-files-recursively directory regexp &optional include-directories
2636Return all files under @var{directory} whose file names match 2636Return all files under @var{directory} whose names match @var{regexp}.
2637@var{match} recursively. The file names are returned depth first, 2637This function searches the specified @var{directory} and its
2638meaning that contents of sub-directories are returned before contents 2638sub-directories, recursively, for files whose basenames (i.e., without
2639of the directories. If @var{include-directories} is non-@code{nil}, 2639the leading directories) match the specified @var{regexp}, and returns
2640also return directory names that have matching names. 2640a list of the absolute file names of the matching files
2641(@pxref{Relative File Names, absolute file names}). The file names
2642are returned in depth-first order, meaning that files in some
2643sub-directory are returned before the files in its parent directory.
2644In addition, matching files found in each subdirectory are sorted
2645alphabetically by their basenames. By default, directories whose
2646names match @var{regexp} are omitted from the list, but if the
2647optional argument @var{include-directories} is non-@code{nil}, they
2648are included.
2641@end defun 2649@end defun
2642 2650
2643@defun directory-files-and-attributes directory &optional full-name match-regexp nosort id-format 2651@defun directory-files-and-attributes directory &optional full-name match-regexp nosort id-format
diff --git a/etc/NEWS b/etc/NEWS
index b9e0bd4ba24..bd7435b1760 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -181,9 +181,6 @@ for use in Emacs bug reports.
181hiding character but the default `.' can be used by let-binding the 181hiding character but the default `.' can be used by let-binding the
182variable `read-hide-char'. 182variable `read-hide-char'.
183 183
184** A new function `directory-files-recursively' returns all matching
185files (recursively) under a directory.
186
187** The new function `directory-name-p' can be used to check whether a file 184** The new function `directory-name-p' can be used to check whether a file
188name (as returned from, for instance, `file-name-all-completions' is 185name (as returned from, for instance, `file-name-all-completions' is
189a directory file name. It returns non-nil if the last character in 186a directory file name. It returns non-nil if the last character in
@@ -1138,6 +1135,10 @@ process filter, sentinel, etc., through keyword arguments (similar to
1138`make-network-process'). 1135`make-network-process').
1139 1136
1140+++ 1137+++
1138** A new function `directory-files-recursively' returns all matching
1139files (recursively) under a directory.
1140
1141+++
1141** New variable `inhibit-message', when bound to non-nil, inhibits 1142** New variable `inhibit-message', when bound to non-nil, inhibits
1142`message' and related functions from displaying messages the Echo 1143`message' and related functions from displaying messages the Echo
1143Area. The output is still logged to the *Messages* buffer. 1144Area. The output is still logged to the *Messages* buffer.
diff --git a/lisp/files.el b/lisp/files.el
index e892ac6b94b..f37c23b7bdd 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -744,11 +744,13 @@ The path separator is colon in GNU and GNU-like systems."
744 (and (> (length name) 0) 744 (and (> (length name) 0)
745 (char-equal (aref name (1- (length name))) ?/))) 745 (char-equal (aref name (1- (length name))) ?/)))
746 746
747(defun directory-files-recursively (dir match &optional include-directories) 747(defun directory-files-recursively (dir regexp &optional include-directories)
748 "Return all files under DIR that have file names matching MATCH (a regexp). 748 "Return list of all files under DIR that have file names matching REGEXP.
749This function works recursively. Files are returned in \"depth first\" 749This function works recursively. Files are returned in \"depth first\"
750and alphabetical order. 750order, and files from each directory are sorted in alphabetical order.
751If INCLUDE-DIRECTORIES, also include directories that have matching names." 751Each file name appears in the returned list in its absolute form.
752Optional argument INCLUDE-DIRECTORIES non-nil means also include in the
753output directories whose names match REGEXP."
752 (let ((result nil) 754 (let ((result nil)
753 (files nil) 755 (files nil)
754 ;; When DIR is "/", remote file names like "/method:" could 756 ;; When DIR is "/", remote file names like "/method:" could
@@ -764,11 +766,11 @@ If INCLUDE-DIRECTORIES, also include directories that have matching names."
764 (unless (file-symlink-p full-file) 766 (unless (file-symlink-p full-file)
765 (setq result 767 (setq result
766 (nconc result (directory-files-recursively 768 (nconc result (directory-files-recursively
767 full-file match include-directories)))) 769 full-file regexp include-directories))))
768 (when (and include-directories 770 (when (and include-directories
769 (string-match match leaf)) 771 (string-match regexp leaf))
770 (setq result (nconc result (list full-file))))) 772 (setq result (nconc result (list full-file)))))
771 (when (string-match match file) 773 (when (string-match regexp file)
772 (push (expand-file-name file dir) files))))) 774 (push (expand-file-name file dir) files)))))
773 (nconc result (nreverse files)))) 775 (nconc result (nreverse files))))
774 776