I have a project base folder, ~/prj, inside of which I have many individual projects, 2014_prj1, 2014_prj2, ..., inside of which I have, among others, a doc folder. The layout looks like this:


Now I'd like to add all project directories (2014_prjX) to org-agenda-files, as well as all doc subdirectories of the project directories. The data folders should not be part of org-agenda-files, because they can possibly contain 10000s of files.

How can I achieve this? I tried a simple

(setq org-agenda-files (quote ("~/doc/notes"

but this gives me the error

Non-existing agenda file ~/prj/*/doc

2 Answers 2


You can use the function file-expand-wildcards to get all the files matching the wildcard add them to org-agenda-files variable. Something like the following

(setq org-agenda-files (append '("~/doc/notes" "~/.emacs.d") (file-expand-wildcards "~/prj/*/doc")))
  • 1
    Is there a hook that would allow the set of files to be computed dynamically? E.g. if I add a new .org file after I start emacs, I would still like it to be part of org-agenda-files. Commented Aug 2, 2018 at 17:17

I created a more generic approach, which allows you to have deeper nesting. For example, I have a rich tree of notes and some folders have tasks.org file in it. This code will collect all of the fly:

(defun set-org-agenda-files ()
  (require 'f)
  (require 's)

  (setq org-agenda-files
    (f-entries org-directory
               (lambda (filename)
                 (s-ends-with-p "/tasks.org" filename))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.