How can I bring all files with names that conform a specific regex, recursively in a directory tree, to a single dired buffer?
So I can rename/delete them all at once?
How can I bring all files with names that conform a specific regex, recursively in a directory tree, to a single dired buffer?
So I can rename/delete them all at once?
Use
M-x find-name-dired
to get files according to a wildcard.
Find all files with suffix "org" in directory "~/org/". Enter the following
M-x find-name-dired
~/org
*org
and enjoy.
Use
M-x find-dired
with suitable arguments to get files according to a regular expression.
Find all files with suffix "org" in directory "~/org/". Enter the following
M-x find-dired
~/org
-regex ".*org$"
and enjoy.
To use a regex, you might also try find-lisp-find-dired
.
This command belongs to the standard lib. find-lisp, which is entirely
written in elisp i.e., you don't need to have installed an external
find
program.
For instance, the following shows all the files with extension '.el' under the directory ~/lisp:
M-x find-lisp-find-dired RET ~/lisp RET \.el\' RET
(The match honors case-fold-search
).
It's worth to note that since the next Emacs release (v26.1) Dired supports wilcards in the directory part of the file name argument. That means the following works:
C-x d ~/soft/*/*.c RET
(The match is case-sensitive).
This command shows in a Dired buffer all the files with extension '.c', 2 depth levels under '~/soft'. That means, all files like '~/soft/foo/bar.c' will be listed, but not files like '~/soft/qux.c' nor '~/soft/foo/baz/qux.c'.
The same but case-insensitive:
C-x d ~/soft/*/*.[cC] RET
If you are running Dired with a 'ls' implemented in elisp, 'ls-lisp' or 'eshell-ls', then you can recursively list all the files matching a wildcard with the following syntaxis:
C-x d ~/soft/**/*.c RET
Note the '**'. In this case all files under '~/soft' matching the wildcard are shown, even '~/soft/qux.c'.
However, when you are using insert-directory-program
the wildcard expansion is made by the system shell; that means,
this recursive '**' syntaxis just works if it's supported by your shell.
For instance zsh does support it, but bash doesn't. With shells other
that zsh the previous command will do the same as:
C-x d ~/soft/*/*.c RET