确定一个文件是否存在
(file-exists-p "~/test.el")
看看它的帮助文档:
file-exists-p is a built-in function in `C source code'.
(file-exists-p FILENAME)
Return t if file FILENAME exists (whether or not you can read it.)
See also `file-readable-p' and `file-attributes'.
This returns nil for a symlink to a nonexistent file.
Use `file-symlink-p' to test for such links.
如果存在则返回t
检查一个文件是否存在且可读
(file-readable-p "~/test.el")
检查文件的属性
(file-attributes "~/test.el" 'string)
或者
(file-attributes "~/test.el" 'integer)
可以通过这个获得一个文件是否是目录的信息。
一个目录操作的例子
假定一个目录下的子目录名称都是数字,查找数字最大的那个目录名称。
(setq file-name-list (directory-files "/opt/share/upland_release" nil "[0-9]+" 'nosort))
(string-to-number (car file-name-list))
其他文件函数请参考
http://www.gnu.org/software/emacs/manual/html_mono/elisp.html的File相关章节。