[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] How to let Org Agenda search all files in a directory *recursive
From: |
Suvayu Ali |
Subject: |
Re: [O] How to let Org Agenda search all files in a directory *recursively* ? |
Date: |
Fri, 28 Jun 2013 01:40:26 +0200 |
User-agent: |
Mutt/1.5.21 (2012-12-30) |
On Thu, Jun 27, 2013 at 03:53:53PM +0800, chris wrote:
> I want to set up Org-mode variable "org-agenda-files".
>
> How to Let [C-c a] to search over all files in a directory *recursively* ?
You can try this function:
;; recursively find .org files in provided directory
;; modified from an Emacs Lisp Intro example
(defun find-org-file-recursively (directory &optional filext)
"Return .org and .org_archive files recursively from DIRECTORY.
If FILEXT is provided, return files with extension FILEXT instead."
(interactive "DDirectory name: ")
(let* (org-file-list
(case-fold-search t) ; filesystems are case sensitive
(fileregex (if filext (format "^[^.#].*\\.\\(%s$\\)" filext)
"^[^.#].*\\.\\(org$\\|org_archive$\\)"))
(cur-dir-list (directory-files directory t "^[^.#].*"))) ; exclude .*
;; loop over directory listing
(dolist (file-or-dir cur-dir-list org-file-list) ; returns org-file-list
(cond
((file-regular-p file-or-dir) ; regular files
(if (string-match fileregex file-or-dir) ; org files
(add-to-list 'org-file-list file-or-dir)))
((file-directory-p file-or-dir)
(dolist (org-file (find-org-file-recursively file-or-dir filext)
org-file-list) ; add files found to result
(add-to-list 'org-file-list org-file)))))))
I'm pretty sure there are a few bugs, so test well.
--
Suvayu
Open source is the future. It sets us free.