0

I've got an image and I need to duplicate it 800 times but add a new prefix every time I duplicate it. I've got the prefixes in a CSV file (or spreadsheet) and I'm wondering if there's a way that I can have Automator (or some other automation) program duplicate the image but rename the image with the different prefixes.

I'm aware of how to duplicate multiple images with the same prefix but is it possible to duplicate one image multiple times with different prefixes. Thanks for your help!

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.

  • Interesting. I'll give that a shot. Thanks, I'll come back once I see if that works. – MxmastaMills Sep 10 '13 at 23:28
  • Worked like a charm. Thank you so much. I'll be using this script quite a lot. – MxmastaMills Sep 10 '13 at 23:45
  • One interesting thing is that the script ignored the last line of prefixes.txt file. Do you know why that would be happening? – MxmastaMills Sep 10 '13 at 23:46
  • 1
    @MxmastaMills most Unix-y things (including the bash shell running the script) expect a blank line at the end of a file, so if your file didn’t have one, that’s likely the reason. Further details if you want: stackoverflow.com/questions/14544636/… – robmathers Sep 11 '13 at 0:02
  • 1
    @MxmastaMills just added a new version that does what you’re looking for. – robmathers Sep 11 '13 at 3:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .