Renaming from a CSV. Combining the existing name with new data

Advanced Renamer forum
#1 : 03/04-23 12:54
Andy Gilbert
Andy Gilbert
Posts: 3
I have a csv file containing the image name in one column, e.g. “12345” which matches the SKU.
I also have another column containing the product tile e.g. “My Fantastic Widget”.
The images could be in different formats e.g. “12345.jpg” or “12345.png”.
I need to rename the file “12345-my-fantastic-widget.jpg” or “12345-my-fantastic-widget.png” keeping the original extension.
How do I do this?


03/04-23 12:54
#2 : 05/04-23 10:05
David Lee
David Lee
Posts: 1125
Use a Script method.

Generate a lookup table in the Pre batch script by reading lines from your csv file using the <File Line> tag.

Pre batch script:

csv = "C:\\My\\File\\Path\\CSVfile.csv";
csv = '::\"' +csv + '\"';
var list = {};
j=1;
while (line = app.parseTags('<File Line:' + j + csv + '>')) {
match = line.match(/(.*),(.*)/);
list[match[1]] = '-' + match[2].toLowerCase().replace(/[ ]/g, '-');
j++;
}

Main script:

if (title = list[item.name]) return item.name + title;

Apply to: Name

Edit the first line of the Pre batch script to match the full file path to your csv file, replacing the "\" separator with "\\"

This script assumes that the sku is saved in the first column of the csv file as TEXT, not a number, using a comma as separator.



05/04-23 10:05
#3 : 05/04-23 12:38
Andy Gilbert
Andy Gilbert
Posts: 3
Reply to #2:
That's great, it worked thank you.


05/04-23 12:38