1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-14 16:50:58 +00:00

Implement a new function `directory-name-p'

* doc/lispref/files.texi (Relative File Names): Mention
`directory-name-p'.

* etc/NEWS: Mention directory-name-p.

(directory-name-p): New function.
(directory-files-recursively): Use it.
This commit is contained in:
Lars Magne Ingebrigtsen 2014-12-13 16:10:04 +01:00
parent 3e8e971356
commit 987d2f9421
6 changed files with 26 additions and 1 deletions

View File

@ -1,3 +1,7 @@
2014-12-13 Lars Magne Ingebrigtsen <larsi@gnus.org>
* files.texi (Relative File Names): Mention `directory-name-p'.
2014-12-13 Eli Zaretskii <eliz@gnu.org>
* text.texi (Comparing Text): Prevent a text string from being

View File

@ -2020,6 +2020,11 @@ form.
@end example
@end defun
@defun directory-name-p filename
This function returns non-@code{nil} if @var{filename} ends with a
forward slash (@samp{/}) character.
@end defun
@node Directory Names
@subsection Directory Names
@cindex directory name

View File

@ -1,3 +1,7 @@
2014-12-13 Lars Magne Ingebrigtsen <larsi@gnus.org>
* NEWS: Mention directory-name-p.
2014-12-09 Lars Magne Ingebrigtsen <larsi@gnus.org>
* NEWS: Mention directory-files-recursively.

View File

@ -140,6 +140,11 @@ library function `ftw'.
** A new function `directory-files-recursively' returns all matching
files (recursively) under a directory.
** The new `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
the name is a forward slash.
* Editing Changes in Emacs 25.1

View File

@ -2,6 +2,8 @@
* files.el (directory-files-recursively): Really check whether
files are symlinks.
(directory-name-p): New function.
(directory-files-recursively): Use it.
2014-12-13 Artur Malabarba <bruce.connor.am@gmail.com>

View File

@ -761,6 +761,11 @@ prevented. Directory entries are sorted with string-lessp."
(file-name-nondirectory dir)
args))))
(defsubst directory-name-p (name)
"Return non-nil if NAME ends with a slash character."
(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).
This function works recursively. Files are returned in \"depth first\"
@ -771,7 +776,7 @@ If INCLUDE-DIRECTORIES, also include directories that have matching names."
(dolist (file (sort (file-name-all-completions "" dir)
'string<))
(unless (member file '("./" "../"))
(if (= (aref file (1- (length file))) ?/)
(if (directory-name-p file)
(let* ((leaf (substring file 0 (1- (length file))))
(path (expand-file-name leaf dir)))
;; Don't follow symlinks to other directories.