Let's say I'd like to know how many .png images I have in a folder. In shell I'd run:
ls -1 | grep .png | wc -l
Is there a way to achieve this in emacs (preferably not just reading in from a shell output)?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityLet's say I'd like to know how many .png images I have in a folder. In shell I'd run:
ls -1 | grep .png | wc -l
Is there a way to achieve this in emacs (preferably not just reading in from a shell output)?
(length (directory-files "~/Pictures" nil "\\.png\\'"))
See C-hf directory-files
.png
and .jpeg
, how would the regex look like? I tried [(.png)|(.jpeg)]
, but it matches other things too.
– dangom
May 30 '16 at 9:56
"\\.\\(png\\|jpeg\\)\\'"
will do the trick in Emacs.
– phils
May 30 '16 at 10:53
rx
regexp compiler like so: (rx "." (or "png" "jpeg") string-end)
– phils
May 30 '16 at 10:59
In dired (in directory in which you want to count .png files)
run M-x eshell-command
:
(length (directory-files "" nil "\\.png\\'"))