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
- 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.
- 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.