Copy and rename files applescript or shell script

I'm trying to find an quick an easy way to copy and rename some files. Ideally a droplet or something like that.


BLABLABLA.jpg should be copied and/or duplicated and rename to BLABLABLA-DE.jpg, BLABLABLA-FR.jpg, BLABLABLA-IT.jpg, BLABLABLA-ES.jpg


Basically adding country codes ES, FR, IT, DE to my original file/s BLABLABLA.jpg and TRALALA.jpg and HOOPLA.jpg at the same time.


Any ideas ?


Posted on Feb 28, 2019 12:15 AM

Reply
4 replies

Feb 28, 2019 2:42 AM in response to adrian_30

This shell script should do what you want. Change the first two lines to your file path and, if necessary, a different extension. You can add or subtract country codes as needed.


NOTE: I delete the original file in the last line (rm "$f"), so if you don't want this to happen comment it out or remove.


Ensure you have original files backed-up before trying!


#!/bin/bash

filepath="/Users/path/to/folder/";
extension=".jpg";
countries=('DE' 'ES' 'FR' 'IT');

for f in "$filepath"*"$extension"; do
	filename=$(basename "$f");
	filename="${filename%.*}";
	for c in "${countries[@]}"; do
		cp -v "$f" "$filepath$filename-$c$extension";
	done;
	rm "$f";
done;




This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Copy and rename files applescript or shell script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.