4

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?

1 Answer 1

8

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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