If you use library Dired+ then you can use command
diredp-do-eval-in-marked-recursive to do what you want.
If you use it directly it asks you for a sexp to evaluate at the beginning of each file to be acted on. In this case, the sexp you want is just a
So this simple command does the job:
(defun bar ()
'(replace-string "import org.apache.log4j.Logger;"
diredp-do-eval-in-marked-recursive is bound by default to key sequence
M-+ @ M-:. It's also on menu-bar menu Multiple > Marked Here and Below > Apply (Map) > Eval Sexp In.
diredp-do-eval-in-marked-recursive is an interactive Lisp function in
(diredp-do-eval-in-marked-recursive SEXP &optional IGNORE-MARKS-P DETAILS)
SEXP in each of the marked files, including in marked subdirs.
diredp-do-eval-in-marked but act recursively on subdirs, and do
no result-logging, error-logging, or echoing.
The files included are those that are marked in the current Dired
buffer, or all files in the directory if none are marked. Marked
subdirectories are handled recursively in the same way.
With a prefix argument, ignore all marks - include all files in this
Dired buffer and all subdirs, recursively.
When called from Lisp, optional arg
DETAILS is passed to
[All of the Dired+ commands that act on marked files not only in the current Dired buffer but also in Dired buffers for any subdirs in that buffer that are themselves marked, and so on, recursively, are on prefix key
M-+. Those that apply a function, evaluate a sexp, or invoke a command are on prefix key
M-+ @. And
M-: is mnemonic for evaluating a sexp. (The same is true of the non-"recursive" commands - same key bindings, but without the