file - Emacs 口齿不清 : How can I get the newest file in a directory?

标签 file emacs directory elisp

给定目录的路径,如何返回该目录中最新文件的路径?

最佳答案

使用内置 API 也可以实现:

(defun latest-file (path)
  "Get latest file (including directory) in PATH."
  (car (directory-files path 'full nil #'file-newer-than-file-p)))

(latest-file "~/.emacs.d") ;; => "/Users/xcy/.emacs.d/var"

如果您还需要子目录下的文件,请使用 directory-files-recursively而不是 directory-files .如果要排除目录,请先使用 file-directory-p 过滤文件/目录列表。 .

关于file - Emacs 口齿不清 : How can I get the newest file in a directory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30886282/

相关文章:

c - fgets 存储文本文件中的未知数据

c++ - 如何将文本文件复制到另一个文件?

c# - 从完整文件路径获取文件夹名称

eclipse - 任何类似于 Emacs 对 Eclipse 的缓冲区/窗口支持的东西?

复制c中的子目录

directory - teSTLink 安装失败 : checking if/var/teSTLink/logs/directory exists

multithreading - Camel 文件使用者模板 - 线程保持事件状态

sql - pgAdmin 4 在查询执行后不显示结果 (postgreSQL)

emacs - 在 Emacs 中,如何启用自动隐藏可怕的细节?

emacs - 在 emacs 中使用 gnus 从 microsoft exchange(2010) 访问邮件