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
  • 2819 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

Two more questions

1. How can I assign a hotkey to the script now? I know how to create them in PS but not seeing this option in Bridge? I am using Windows 10.

2. For the script, would there be something I can add to the existing script that will select the copy the first image to another folder within the same directory?

For Example:

Main Directory:

9831983.jpg

9831983a.jpg

9831983b.jpg

9831983c.jpg

9831983d.jpg

Main Directory>Thumbails:

9831983.jpg

I've made an adjustment to the code and the first step is working well with my modifications, just realized about the above part in mention:

#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', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];

    try{

        newName = prompt('REF NUMBER');

        if(newName != null){

            newNameU = newName.toLowerCase();

            for (var a in thumbs){

                var selectedFile = thumbs.spec;

                Title = selectedFile.name;

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

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

                counter++;

                }

            }

        }

    catch(e){

        }

    app.document.refresh();

    app.synchronousMode = false;

    }

andrewn63997035
Participating Frequently
January 28, 2019

That's just the syntax you would use. You'll need to add it to the existing script or write the rest of it to work.


Sorry for being too needy but I tried to do it several different ways and it kept throwing me errors. Where would I add this to the existing script? I don't know this too well :/ So with that script let's say the root folder is JPEG I'm working in and I need the first image of each set to be moved to THUMBNAIL within the existing script? This is all new to me

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.