Skip to main content
andrewn63997035
Participating Frequently
January 24, 2019
Answered

Script to batch rename, have first file as a number, the rest sequential alphabetical

  • January 24, 2019
  • 5 replies
  • 2845 views

I just can't seem to figure this one out! The database I'm working with has a rule that the first image needs to be numerical and the rest of the image span to be sequential alphabetical.

For example, I'll have these images:

IMG_2013.jpg

IMG_2014.jpg

IMG_2015.jpg

IMG_2016.jpg

IMG_2017.jpg

and need to rename them for whatever the UPC is, for example:

982371818.jpg

982371818a.jpg

982371818b.jpg

982371818c.jpg

982371818d.jpg

This topic has been closed for replies.
Correct answer Lumigraphics

You really need a script for this. Is there a list of what files use what filenames? I have a rename script that I use in production, this is a modified version that will accept an input and rename selected files based on that. You could enumerate as many variants as you needed.

#target bridge

if(BridgeTalk.appName == 'bridge'){

    FT = MenuElement.create('command', 'Rename', 'at the end of Tools');

    FC = MenuElement.create('command', 'Rename', 'after Thumbnail/Open', this.menuID);

    }

FT.onSelect = function(){

    Renamer1();

    }

FC.onSelect = function(){

    Renamer1();

    }

function Renamer1(){

    app.synchronousMode = true;

    var thumbs = app.document.selections;

    var newName = '';

    var newNameU = '';

    var Title = [];

    var counter = 0;

    var variant = ['a', 'b', 'c', 'd'];

    try{

        newName = prompt('Enter part number');

        if(newName != null){

            newNameU = newName.toUpperCase();

            for (var a in thumbs){

                var selectedFile = thumbs.spec;

                Title = selectedFile.name;

                Title = (Title.split( '.' ))[0];

                thumbs.name = thumbs.name.toUpperCase();

                thumbs.name = newNameU + variant[(counter)] + '.jpg';

                counter++;

                thumbs.name = thumbs.name.toUpperCase();

                }

            }

        }

    catch(e){

        }

    app.document.refresh();

    app.synchronousMode = false;

    }

Chuck Uebele
Community Expert
Community Expert
January 24, 2019

Moving this thread to the Bridge Scripting forum.

LumigraphicsCorrect answer
Legend
January 24, 2019

You really need a script for this. Is there a list of what files use what filenames? I have a rename script that I use in production, this is a modified version that will accept an input and rename selected files based on that. You could enumerate as many variants as you needed.

#target bridge

if(BridgeTalk.appName == 'bridge'){

    FT = MenuElement.create('command', 'Rename', 'at the end of Tools');

    FC = MenuElement.create('command', 'Rename', 'after Thumbnail/Open', this.menuID);

    }

FT.onSelect = function(){

    Renamer1();

    }

FC.onSelect = function(){

    Renamer1();

    }

function Renamer1(){

    app.synchronousMode = true;

    var thumbs = app.document.selections;

    var newName = '';

    var newNameU = '';

    var Title = [];

    var counter = 0;

    var variant = ['a', 'b', 'c', 'd'];

    try{

        newName = prompt('Enter part number');

        if(newName != null){

            newNameU = newName.toUpperCase();

            for (var a in thumbs){

                var selectedFile = thumbs.spec;

                Title = selectedFile.name;

                Title = (Title.split( '.' ))[0];

                thumbs.name = thumbs.name.toUpperCase();

                thumbs.name = newNameU + variant[(counter)] + '.jpg';

                counter++;

                thumbs.name = thumbs.name.toUpperCase();

                }

            }

        }

    catch(e){

        }

    app.document.refresh();

    app.synchronousMode = false;

    }

andrewn63997035
Participating Frequently
January 24, 2019

I will give this a try!

So how it works is the client gives me a spreadsheet that has three columns. One is the UPC, Title Description (not important on my end) and the image span. For Example:

UPC                    Description                    Image Number

982371818      Fleece Blanket         2013-2017

All 2400 images are in the same folder. To answer a few other individuals questions the image sequences are under 27 images. They are usually 8-15 images per UPC.

So for this section of the script, I would just keep adding letters to it, perhaps the max images I believe would correlate up to Z if needed yet?

    var variant = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z];

I appreciate everyone's input on this so far. I've been a designer for over a decade and have recently been getting into larger scale production levels.

Chuck Uebele
Community Expert
Community Expert
January 24, 2019

Also, how many images do you have within a set of UPC codes? 27 or less?

Stephen Marsh
Community Expert
Community Expert
January 24, 2019

Further to Chuck’s second suggestio, I’d just select one file then batch rename without the sequential alpha character/s.

Then invert the selection and batch rename again, adding the sequential alpha.

Should be pretty fast to do with keyboard shortcuts and presets.

andrewn63997035
Participating Frequently
January 24, 2019

I have over 2400 images and there are over 800 image sets. How can I invert the selection? I understand the batch rename for the singular image but don't know what you mean by inverting the selection to name the rest. Thanks for any additional input!

Chuck Uebele
Community Expert
Community Expert
January 24, 2019

How do you get the UPC number? Is it a folder name?

Chuck Uebele
Community Expert
Community Expert
January 24, 2019

Without a script, the only way to do that is to manually rename the first file, then use the batch rename to do the rest.

andrewn63997035
Participating Frequently
January 24, 2019

I'm looking for a script solution if possible. I have over 800 UPC tied image sets to work on.  That way would double the workload, but appreciate the suggestion.