+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
@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
+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.
** 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.
+
\f
* Editing Changes in Emacs 25.1
* 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>
(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\"
(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.