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

zancine

macrumors newbie
Original poster
Mar 14, 2018
2
0
Hi there, I have quite many images files need to be named following a pattern, and the pattern goes like:

Section_1_1_NAME.jpg
Section_1_2_NAME.jpg
Section_1_3_NAME.jpg
Section_1_4_NAME.jpg
Section_1_5_NAME.jpg

Section_2_1_NAME.jpg
Section_2_2_NAME.jpg
Section_2_3_NAME.jpg
Section_2_4_NAME.jpg
Section_2_5_NAME.jpg

....and so on, where NAME keep being the same all the way.
The tricky part is for every 5 items, the first number increase by 1.
The original file names are in sequence, e.g. "file.001.jpg"

I am not a programmer but I guess this can be done with terminal to run commands and batch rename a whole folder of images?
I tried with automator but can't really figure out how to get that tricky part done.

It'd be a life saver if anyone can come up with a solution, as I have a lot of files need to be named that way.

Thanks!
 

Toutou

macrumors 65816
Jan 6, 2015
1,082
1,575
Prague, Czech Republic
Copy this into terminal, press enter. DO NOT RUN ON YOUR ORIGINAL FILES, make a backup. This script renames everything, including any folder inside the target folder. So better create a new one and put your files inside it.
Code:
bash -c 'clear;echo "Please drag n drop the target folder into this window.";echo "Should look like this: /path/to/folder";echo -n "Input: ";read folder;cd $folder;if [ $? -ne 0 ];then echo "Wrong input, cant access directory, aborting";read;exit;fi;I=0;for filename in *;do let "A=(I/5)+1";let "B=I%5+1";newname="Section_$A""_$B""_$filename";echo "Renaming $filename to $newname";mv "$filename" "$newname";let "I++";done;echo "---All done!---";read'
 

zancine

macrumors newbie
Original poster
Mar 14, 2018
2
0
Thanks a lot Toutou, that works like a charm!
Just amazing it all get done in a blink.

Thank you so much !!!!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.