我正在寻找一种方法来定期检查某个目录下的文件是否从上次检查更改(功能符号到FAM守护程序或gio.monitor_directory).在emacs lisp中.
(defun install-monitor (file secs)
(run-with-timer
0 secs
(lambda (f p)
(unless (< p (second (time-since (elt (file-attributes f) 5))))
(message "File %s changed!" f)))
file secs))
(defvar monitor-timer (install-monitor "/tmp" 5)
"Check if /tmp is changed every 5s.")
Run Code Online (Sandbox Code Playgroud)
取消,
(cancel-timer monitor-timer)
Run Code Online (Sandbox Code Playgroud)
正如mankoff所述,上面的代码片段监视最近5秒内的文件修改,而不是自上次检查以来.为了实现后者,我们每次进行检查时都需要保存属性.希望这有效:
(defvar monitor-attributes nil
"Cached file attributes to be monitored.")
(defun install-monitor (file secs)
(run-with-timer
0 secs
(lambda (f p)
(let ((att (file-attributes f)))
(unless (or (null monitor-attributes) (equalp monitor-attributes att))
(message "File %s changed!" f))
(setq monitor-attributes att)))
file secs))
(defvar monitor-timer (install-monitor "/tmp" 5)
"Check if /tmp is changed every 5s.")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1427 次 |
最近记录: |