Jump to content

Batch-rename file extensions in subfolders


Michel Gilbert

Recommended Posts

Hi,

 

I've been trying to batch-rename all my Notes and User Lexicon .bww files (that I copied into a separate folder) to .rtf files (so I can search them with Orbis). So far, I've tried the Terminal and Automator, and I can't figure out a way to include subdirectories.

 

In the Terminal, this works for the directory you are in:

 

for file in *.bww; do mv "$file" "${file%.txt}.rtf"; done

 

Does anyone know the syntax to include subfolders/directories as well?

 

Thanks,

 

Michel

Link to comment
Share on other sites

I use A Better Finder Rename (weird name but very useful) for such things. I’m pretty sure it will do everything you’re wanting and give you a nice little interface to do it in, too. 

  • Like 1
Link to comment
Share on other sites

If they are all in 1 main folder (assuming there are subfolders below, since you're asking about recursion), you can use the built-in Finder Rename function (I'm also assuming MacOS, as you've mentioned Automator).

 

https://superuser.com/questions/1020027/recursive-batch-rename-files (the first answer)

 

Might be easier than remembering this:

find . -depth -name "\.bww" -execdir sh -c 'mv {} $(echo {} | sed "s/\.bww/.rtf/")' \;
Edited by Graham Buck
  • Like 1
Link to comment
Share on other sites

Hi Graham,

 

Thanks.

 

I tried the built-in method before posting and I got the message, "Are you sure you want to change the extension from ".bww" to ".rtf"? . . .  and I got the choice to Keep .bww or Use .rtf. The problem is that it asks for one file at a time, and there are over 6000 of them. I didn't see an option to change them all at the same time.

 

I opened the Terminal, navigated to Documents/Notes, checked with ls, copied and pasted your syntax, and nothing happened. I'm way in over my head, perhaps I was supposed to substitute something.

 

Regards,

 

Michel

Link to comment
Share on other sites

hmm, it's be a while since I've done much scripting from bash. Maybe remove the '\' from in front of the first period?

find . -depth -name ".bww" -execdir sh -c 'mv {} $(echo {} | sed "s/\.bww/.rtf/")' \;

Also, not sure why I didn't suggest this above, but a free and very lightweight tool I use a bunch is PowerRenamer

 

Just search in Finder for .bww, select all, run the program and fill in the blanks. You can even do a preview to make sure the rename doesn't bork anything.

  • Like 1
Link to comment
Share on other sites

 Maybe remove the '\' from in front of the first period?

 

That did it, worked perfectly. Thank you, and the Lord bless you. :)

  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...