2

I have many files in many directories all with the same filename pattern. I want to rename them by replacing a substring with another, e.g. bla_A.mat to bla_B.mat.

I know I can do this quite easily in a directory using wdired mode and replace-string. How can I do that same operation recursively on all my directories?

6

Here's one way to do this with dired:

  1. M-xfind-name-dired RET select the top-level directory where all such files exist, RET bla-*.mat.
  2. t will mark all files in the buffer.
  3. %R \(.*\)_A\.mat RET \1_B.mat RET.

More on renaming files: https://www.gnu.org/software/emacs/manual/html_node/emacs/Transforming-File-Names.html#Transforming-File-Names

  • 1
    Worked great thanks - I actually used wdired after step 1 so I check I hadn't screwed up first. – jarmond Mar 20 '15 at 11:50
  • 1
    C-u s R RET in the dired buffer lists all files recursively also. – politza Mar 20 '15 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.