Function: search-directory-tree

search-directory-tree is a byte-compiled function defined in bib-cite.el.

Signature

(search-directory-tree DIRECTORIES EXTENSION-REGEXP RECURSE FIRST-FILE)

Documentation

Return a list of all reachable files in DIRECTORIES ending with EXTENSION.

DIRECTORIES is a list or a single-directory string EXTENSION-REGEXP is actually (any) regexp, usually \\.bib$ If RECURSE is t, then we will recurse into the directory tree,
              nil, we will only search the list given.
If FIRST-FILE is t, stop after first file is found.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/bib-cite.el
(defun search-directory-tree (directories extension-regexp recurse first-file)
  "Return a list of all reachable files in DIRECTORIES ending with EXTENSION.
DIRECTORIES is a list or a single-directory string
EXTENSION-REGEXP is actually (any) regexp, usually \\\\.bib$
If RECURSE is t, then we will recurse into the directory tree,
              nil, we will only search the list given.
If FIRST-FILE is t, stop after first file is found."
  (or (listp directories)
      (setq directories (list directories)))

  (let (match)
    (while directories
      (let* ((directory (file-name-as-directory  (car directories)))
             (content (and directory
                           (file-readable-p directory)
                           (file-directory-p directory)
                           (directory-files directory))))
        (setq directories (cdr directories))
        (while content
          (let ((file (expand-file-name (car content) directory)))
            (cond ((string-match "[.]+$" (car content))) ;This or parent dir
                  ((not (file-readable-p file)))
                  ((and recurse
                        (file-directory-p file))
                   (setq directories
                         (cons (file-name-as-directory file) directories)))
                  ((string-match extension-regexp
                                 (file-name-nondirectory file))
                   (and first-file
                        (setq content nil
                              directories nil))
                   (setq match (cons file match)))))
          (setq content (cdr content)))))

    match))