I want to get a list of all files with specific extension in a directory, and then pass it as an argument. How to do it in ELisp?
No, you do not need any extra filtering. directory-files
does everything you want, i.e., including the filtering to match the extension (e.g. ext
):
(directory-files DIRECTORY nil "\\.ext$")
See C-h f directory-files
. For the current directory, you can use:
(directory-files default-directory nil "\\.ext$")
directory-files
retrieves all the files in a directory as a list. remove-if-not
removes list entries not matching a predicate.
(require 'cl)
(remove-if-not (lambda (filename) (eq "ext" (file-name-extension filename)))
(directory-files dir) )
(I'd love to avoid the (require 'cl)
there. http://emacswiki.org/emacs/ElispCookbook#toc38 has some hints.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With