From mboxrd@z Thu Jan 1 00:00:00 1970 From: Suvayu Ali Subject: Re: How to let Org Agenda search all files in a directory *recursively* ? Date: Fri, 28 Jun 2013 01:40:26 +0200 Message-ID: <20130627234026.GD17935@kuru.dyndns-at-home.com> References: <20130627075135.GA4761@stardiviner> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsLnl-00029P-Ga for emacs-orgmode@gnu.org; Thu, 27 Jun 2013 19:40:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UsLnj-0000ZK-7I for emacs-orgmode@gnu.org; Thu, 27 Jun 2013 19:40:33 -0400 Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]:35123) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsLnj-0000Yp-1A for emacs-orgmode@gnu.org; Thu, 27 Jun 2013 19:40:31 -0400 Received: by mail-wi0-f182.google.com with SMTP id m6so209636wiv.3 for ; Thu, 27 Jun 2013 16:40:30 -0700 (PDT) Received: from kuru.dyndns-at-home.com (sd44012d5.adsl.online.nl. [212.64.18.213]) by mx.google.com with ESMTPSA id p1sm20489173wix.9.2013.06.27.16.40.28 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 27 Jun 2013 16:40:29 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20130627075135.GA4761@stardiviner> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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.