Skip to content

Instantly share code, notes, and snippets.

@tkhoa2711
Created October 13, 2015 01:42
Show Gist options
  • Save tkhoa2711/a09039571b0ac437758f to your computer and use it in GitHub Desktop.
Save tkhoa2711/a09039571b0ac437758f to your computer and use it in GitHub Desktop.
Find the last modified file within a directory
(defun last-modified-file (parent-dir &optional pattern)
"Get the last modified file under `parent-dir'.
A regex `pattern' can be provided to only look for those that match."
(let ((default-directory parent-dir))
(first
(sort
(directory-files default-directory 'absolute pattern 'nosort)
(lambda (x y)
(time-less-p (nth 5 (file-attributes y))
(nth 5 (file-attributes x))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment