Search code examples
emacselisporg-mode

Append org-agenda-files with files of another directory


So i try to create a list of string in the form

"a" "b" "c"

This is a list of files which i want to pass to org-agenda-files As for now this looks like this

(setq org-agenda-files "~/.tasks.org")

Now i need to add some files coming from a directory. i can get those with directory-files-recursively "~/orgroam/daily" "\\[^.].*\.org\'". this will return lets say ("~/b" "~/c")`.

The problem comes when i try to concatenate the "a". What i have tied so far is

(list "~/.tasks.org" (mapconcat #'identity (directory-files-recursively "~/orgroam/daily" "\\`[^.].*\\.org\\'") " "))

and

(concat "~/.tasks.org " (mapconcat #'identity (directory-files-recursively "~/orgroam/daily" "\\`[^.].*\\.org\\'") " "))

but this returns "a" "b c" and "a b c"

Another thing i tried out is to add the result of directory-files-recursively after the (setq org-agenda-files '("~/.tasks.org")) using add-to-list. in this case i get Wrong type argument: stringp, ("~/orgroam/daily/2022-01-19.org" "~/orgroam/daily/2022-01-28.org"....)

Does anyone have a suggestion to achieve the desired output for org-agenda-files?


Solution

  • If you want to include all org files from another directory, you can:

    (setq org-agenda-files '("~/.tasks.org"
                             "~/orgroam/daily/"))
    

    If you still want to append files, you can:

    (setq org-agenda-files (append
                            '("~/.tasks.org")
                            (directory-files-recursively "~/Documents/Org/notes/" "\\`[^.].*\\.org\\'")))
    

    As a friendly reminder, numerous Org files may cause Agenda to be very slow, you can refer to this blog.