Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

KBS756

macrumors 6502a
Original poster
Jan 27, 2009
548
14
I have a bunch of images in a folder and say I want to do something like the following to them

The original image name is

2575-W.jpg

Say I now want to take the first 4 digits and and add 645 to them to get 3219

how would I do this in automator any other mac application


(I have like 5,000 photos I need to do this for)

Thanks in advance
 
I have a bunch of images in a folder and say I want to do something like the following to them

The original image name is

2575-W.jpg

Say I now want to take the first 4 digits and and add 645 to them to get 3219

how would I do this in automator any other mac application


(I have like 5,000 photos I need to do this for)

Thanks in advance

Could do this with a simple shell script.

Is every file in this folder named dddd-W.jpg (where each d represents a digit)?

Do you want to add 644 or 645? In any case you want to add the same number to each dddd?
 
Could do this with a simple shell script.

Is every file in this folder named dddd-W.jpg (where each d represents a digit)?

Do you want to add 644 or 645? In any case you want to add the same number to each dddd?

YES I want to add each number to the 4 digit number and replace that in the file name over the original number

can you let me know how to do that ?

thanks
 
YES I want to add each number to the 4 digit number and replace that in the file name over the original number

can you let me know how to do that ?

thanks

I can tell you how to do it, but only if you can precisely answer each of the three questions I asked. Otherwise you're likely to end up with names you don't want.
 
Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7)

Ok the folder has pictures that have 4 digits to start and have a couple variations behind them -w.jpg -y.jpg -w-btpz.jpg like that

And yes I Want to add 645 to all the pictures names exactly that to all of them

Thx in advance
 
OK. This should work.

Open Terminal (in Utilities).

In Terminal, type the following, leaving a space after the d. Don't press return yet.

Code:
cd

Now drag the folder containing the files and drop it into the Terminal window. This will append the folder's path to the cd command.

Now click on the Terminal window to make it active and press return.

To check that things have gone correctly, type

Code:
ls

in Terminal and press return. (That's lowercase-l and s.)

You should see a listing of the files, still with their old names.

If so, then copy and paste the following into Terminal and press return.

Code:
mkdir newdir; for file in *; do oldindex=${file:0:4}; newindex=$((oldindex+645)); cp -p $file ./newdir/$newindex${file:4}; done

You should get a new folder named newdir inside your folder. Inside that folder should be the renumbered files.

Don't worry about the following, which will appear in Terminal:

Code:
cp: newdir is a directory (not copied).

In any case, the original files are not being deleted, just copied and renamed.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.