0

Suppose I have a list of files:

(setq files '("/path/to/file1" ...))

Is there a way to reduce this list to only those files which were edited within the past, say, 10 days?

1 Answer 1

1

Is there a way to reduce this list to only those files which were edited within the past, say, 10 days?

Something like this? It assumes Emacs 26+, but to support earlier versions you can easily replace (file-attribute-modification-time ...) with (nth 5 ...), seq-filter with other ways of filtering lists, the nil argument to time-subtract with (current-time), etc.

(autoload 'seq-filter "seq")

(defun my-files-since (files days)
  "Return subset of FILES modified within the last DAYS."
  (let ((since (time-subtract nil (days-to-time days))))
    (seq-filter (lambda (file)
                  (let* ((attrs (file-attributes file))
                         (mtime (file-attribute-modification-time attrs)))
                    (time-less-p since mtime)))
                files)))

(my-files-since '("/path/to/foo" "bar" ...) 10)

References:

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.