Commit e820f16c authored by Eric S. Raymond's avatar Eric S. Raymond

Added file-tree-walk to files.el.

parent eb608f9e
2014-12-03 Eric S. Raymond <>
* files.el (file-tree-walk): Lisp translation of ANSI ftw(3).
2014-12-02 Glenn Morris <>
* whitespace.el (whitespace-big-indent-regexp): Add :version.
......@@ -729,6 +729,32 @@ The path separator is colon in GNU and GNU-like systems."
(lambda (f) (and (file-directory-p f) 'dir-ok)))
(error "No such directory found via CDPATH environment variable"))))
(defun file-tree-walk (dir action &rest args)
"Walk DIR executing ACTION. Each call gets as arguments DIR, a file path,
and optional ARGS. The ACTION is applied to each subdirectory
before descending into it, and if nil is returned at that point
the descent will be prevented. Directory entries are sorted with
(cond ((file-directory-p dir)
(or (char-equal ?/ (aref dir (1- (length dir))))
(setq dir (file-name-as-directory dir)))
(let ((lst (directory-files dir nil nil t))
fullname file)
(while lst
(setq file (car lst))
(setq lst (cdr lst))
(cond ((member file '("." "..")))
(and (apply action dir file args)
(setq fullname (concat dir file))
(file-directory-p fullname)
(apply 'file-tree-walk fullname action args)))))))
(apply action
(file-name-directory dir)
(file-name-nondirectory dir)
(defun load-file (file)
"Load the Lisp file named FILE."
;; This is a case where .elc makes a lot of sense.
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