I currently use the following to get a list of agenda files for org-mode:

(setq org-agenda-files (directory-files-recursively "~/Org" "\\.org$"))

I'd like to instead get a list of files that are newer than 7 days old so that Emacs doesn't spend a long time reading and parsing all the org files I have.

I know I have to write a defun that takes in a directory and file regex as its 2 parameters, but I'm at a loss with how to then find files newer than 7 days.

  • I think this question may be a duplicate of a question that asked about using recent files. Hopefully someone will find the duplicate and then this question should be closed as a dup.
    – Drew
    Apr 4 at 17:31

You can filter the directory for files newers than 7 days

(defun newer-than-7-days(file)
  (> 7
                   (current-time )
                   (nth 5 (file-attributes file)) ))

(setq org-agenda-files
      (seq-filter #'newer-than-7-days 
                  (directory-files-recursively "~/Documents/Org" "\\.org$")))
  • This is perfect, thank you! You are an awesome person. Do you have a favourite charity I can donate to as a way of saying thank you? Apr 18 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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