2010-08-18 56 views
25

是否有任何库或函数为emacs lisp执行类似bash的glob扩展?emacs lisp列出扩展名为glob的文件

例如:

(directory-files-glob "~/Desktop/*") 
> ("/home/user/Desktop/file1" "/home/user/Desktop/file2") 

如果没有这样的功能没有关于如何实现它任何暗示/建议吗?

编辑:

文件扩展-通配符:

我在做相当正是这个docs也是一个有用的功能发现 此功能扩展了通配符模式模式,返回与之匹配的文件名列表。

+2

谢谢 - file-expand-wildcards正是我想要的 – Greg 2011-11-04 03:25:59

回答

19

退房的文档directory-files

(directory-files "~/Desktop" nil ".") 

注:第三个参数是一个正则表达式 - 而不是通配符。

直接将globbing模式转换为正则表达式。 eshell配备了一个翻译包,您可以使用:

(require 'em-glob) 
(defun directory-files-glob (path) 
    (directory-files (file-name-directory path) 
        nil 
        (eshell-glob-regexp (file-name-nondirectory path)))) 

而且,如果你想完全置身于ESHELL通配符真实(使用目录),有可能是一个办法让。上面假设globbing部分位于路径的非目录部分。

+0

非常感谢你的明确解释和进一步的想法! – pygabriel 2010-08-19 16:05:29

3

f在一致的命名方案下添加了大量的文件和文件路径处理函数。它有一个功能f-glob这正是这么做的:

(f-glob "~/doc/*.org") ; returns a list of files ending with ".org" 
(f-glob "*.org" "~/doc/") ; they all behave the same 
(f-glob "*.org" "~/doc") 
9

不知道为什么这也许忽略它不是在Emacs在2010年,但在当前Emacs至少有功能file-expand-wildcards

(file-expand-wildcards "~/Desktop/*") 

这正是你想要做的..

+0

哦,看到了已经包含这个Q的编辑,但是因为我在这里忽略了它,无论如何我都会留下我的答案 – 2015-05-22 17:17:33