ELisp编程四:文件操作

确定一个文件是否存在

(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)


上面两行list以字符串或者整数list的形式显示文件的属性,从0-11,一共12个属性。

可以通过这个获得一个文件是否是目录的信息。


一个目录操作的例子

假定一个目录下的子目录名称都是数字,查找数字最大的那个目录名称。

(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相关章节。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值