MacOS – Any easy way to search for & replace characters in JPG file names in a folder

automationfindermacosphotos

Have a MacBook Pro 15 (Oct2009 vintage), and am running 10.8 (Mountain Lion).

Is there an easy way to search for and replace chars in JPG file names in a folder file list?

I'm working with over 70,000 JPG images, and close to 1000 duplicate names must be corrected. My preferred solution is to simply change the name prefix of each from 642 to 699. None of my 3 image browsers/editing programs can do this. I've already spent more time looking for an automation solution, than changing them 1 at a time would have taken, but would prefer an automation approach if there is one. The finder search function works great, sadly there doesn't seem to be a replace function to go with it. I'm not a programmer, so am hoping there is something built that might do the job.

Best Answer

Finder is not the tool for this job, but I've always done this sort of thing via Terminal.

To be safe, you should have a backup of your Mac since the mv command will rename everything it finds, and if more files match the "642*" pattern, they will get changed as well.

Here is a snippet of code to get to the folder, find the files starting with 642 and do the edit one by one in an automated fashion. (Obviously changing the path to the real location of your images):

cd "/path/to/your/images"
for i in 642*; do
    mv "$i" "${i/642/699}"
done

This will move all images matching the wildcard 642* (meaning it starts with 642 and the rest of the name can be anything), and moves them in order to rename the 642 to 699. It will overwrite any files that already have the destination file name, so be sure that they are files you don't want.
This assumes that you don't organize your images into subfolders too; change 642* to */642* if this isn't the case.