Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

My camera names its images IMG_0001.jpg, IMG_0002.jpg, IMG_0003.jpg, etc.

I have about a thousand images and would like to rename them without having to do it manually if possible.

Is there a good way to automate the process of renaming them in the reverse order - e.g. IMG_0003.jpg, IMG_0002.jpg, IMG_0001.jpg?

share|improve this question
    
Did you get an answer to your question? It's important for the site to accept an answer if it works for your needs. Not only does it help others with the same question, it rewards the answerer in addition to the upvotes the community has given them. –  bmike Oct 28 '12 at 22:29
    
Sorry - still haven't had a chance to test it out yet. I will accept one when I figure it out. –  Jason Oct 29 '12 at 18:08
    
Thank you. You can also accept the most useful answer and comment that you have not had time to test. Should it change, you can always un-accept an answer and delete a comment that is out of date. Cheers and thanks for keeping the site fed with feedback. –  bmike Oct 29 '12 at 18:11
add comment

5 Answers 5

up vote 8 down vote accepted

You can use an Automator Workflow.

Something like this:

enter image description here

Sort Finder Items step will sort image names descending (IMG_0003.jpg, IMG_002.jpg, IMG_001.jpg).

Make Sequential step will rename them sequentially (IMG_0001.jpg, IMG_0002.jpg, ...).

Copy Finder Items step is optional, just to be sure not to mess with original files.

share|improve this answer
add comment

Name Mangler ($10 and has a free trial) or Name Changer (free/donationware) is also very good for this sort of thing if you're after a nice, simple app.

share|improve this answer
1  
My personal favorite is A Better Finder Rename macupdate.com/app/mac/6322/a-better-finder-rename –  HairOfTheDog Oct 18 '12 at 22:34
add comment

Here's another shell script. You can save it as a normal text file and then run bash /path/to/script.sh from Terminal. Remove the echo to actually rename the files.

cd ~/Pictures/
IFS=$'\n' # the input field separators include space by default
i=1
for f in $(ls -r IMG*.jpg); do 
    echo mv "$f" "IMG_$(printf %04d $i)".jpg
    (( i++ ))
done
share|improve this answer
add comment

You can use the perl rename.pl script looming around the web (for example, from here), and put it into the folder with your image files.

Its usage is simple and documented and it is pretty powerful. To use it for your case, replace MAXIMUM_NUMBER by the number in the last photo, then run:

perl rename.pl 's/IMG_0+(\d+)/"A_IMG_".sprintf("%04d",(MAXIMUM_NUMBER- $1))/xe' *.jpg && perl rename.pl 's/A_//' *.jpg

To explain:

  1. The first rename (before &&) will rename all files to MAXIMUM_NUMBER minus the number already in the file name. It will also prefix the filename with A_ in order to avoid overwriting already existing files.
  2. The second rename simply deletes the A_ from the file names.

Note that the rename.pl script can do much more than that if you ever need more complex renaming.

share|improve this answer
add comment

Try this in the Terminal:

mkdir new
ls IMG* > 1
sort -r < 1 > 2
paste 1 2 | awk '{ print "mv " $1 " new/" $2} ' > 3
. 3

The renamed files will be in the new folder.

Here is a brief explanation of how this works: it creates a script named 3 that does the renaming. For that, it creates a listing of the images in alphabetical order in 1 and in reverse order in 2. Then one line is read from each file and combine into a mv command, which is executed when you run 3. The images are renamed into the new folder to avoid collisions.

share|improve this answer
    
The answser lhf gavin was right, but before step 5, you should exec chmod +x 3 first. –  lyuehh Oct 18 '12 at 14:39
    
Consider explaining what each step of the script does –  HairOfTheDog Oct 18 '12 at 22:40
    
@HairoftheDog, done. Thanks for the nudge. –  lhf Oct 18 '12 at 23:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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