Automate Duplicating and Renaming Images

Solution 1:

I whipped up a quick script that will copy the image for you (it will work with any type of file actually) and rename it from a plain text file with one prefix per line.

#!/bin/bash
file=$1
prefixes=$2
filename=`basename "$file"`
while read line
do
    cp $file "$line-$filename"
done < $prefixes

Put that into a text file, save it as copier.sh. Then in Terminal, run chmod +x copier.sh (make sure you’re in the same directory as where you saved the file, ideally the one with your images in it). Then run ./copier.sh myimage.jpeg prefixes.txt and you should have a bunch of copies with different names.

The prefixes.txt file (or whatever you want to name it) should have one prefix per line (which should be easy to get by copying and pasting from your spreadsheet).


Updated Version With Folders

#!/bin/bash
file=$1
prefixes=$2
filename=`basename "$file"`
foldername=${filename%%.*}
if [ ! -d "$foldername" ]; then
    mkdir "$foldername"
fi
while read line
do
    cp $file "$foldername"/"$line-$filename"
done < $prefixes

That will create a folder with the same name as the original file (if it doesn’t already exist) and place the copies in it.