Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Jan 23, 2019 Jan 23, 2019

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

TOPICS
Scripting
3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 24, 2019 Jan 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.onSele

...
Translate
LEGEND ,
May 09, 2024 May 09, 2024

This isn't really batch renaming. You'd need a script which reads a file and renames one by one. I'm not aware of anything like that but there may be one available online.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2024 May 09, 2024

Ok it turns out I did have a sample script, give this a try.

NOTE THAT THIS IS UNTESTED! TRY IT ON A SAMPLE OF FILES FIRST!

You would need a tab-delimited text file of before - tab - after filenames.

oldname.jpg tab newname.jpg

 

/*
Utility PS Scripts created by David M. Converse ©2018-24

This script renames files from a tab-delimited text file

Last modified 5/9/24

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#target bridge
if(BridgeTalk.appName == 'bridge'){
    try{
        var itemsRen = MenuElement.create('command', 'Rename From File', 'at the end of Tools');

        itemsRen.onSelect = function(){
            renameFromFile();
            }

        function renameFromFile(){
            var renFile = new File('~/Desktop').openDlg('Select Naming Pairs File', '*.txt'); //select naming pairs file
            if(renFile != null){ //open and read in terms file
                renFile.open('r');
                var i = 0;
                var renList = [];
                var renLine = renFile.readln();
                while(renLine != ''){ //read in search terms one line at a time, place in array
                    renList[i] = renLine;
                    renLine = renFile.readln();
                    i = i + 1;
                    }
                renFile.close();
                }
            var renParam = [];
            var renFolder = app.document.presentationPath; //current folder
            for(var j = 0; j < renList.length; j++){
                renParam = renList[j].split('\t'); //split old and new names
                if(renParam[0] != '' && renParam[1] != ''){ //both specified
                    var renTarget = new Thumbnail(renFolder + '/' + renParam[0]); //find file
                    renTarget.name = (renParam[1]); //rename
                    }
                }
            }
        }
    catch(e){ //oops
        Window.alert(e + ' ' + e.line);
        }
    }

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 09, 2024 May 09, 2024

Thank you for hunting this down, I really appreciate you taking the time to help me out. However is there any way possible that we can rename using Excel CSV instead of a text file?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2024 May 09, 2024

Yes you could modify the script, or just save from Excel as a tab-delimited text file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2024 May 10, 2024
LATEST

@Ashley32242894z7cr – Untested, however, the following 2 changes from the existing code should allow you to work with CSV:

 

var renFile = new File('~/Desktop').openDlg('Select Naming Pairs File', '*.csv'); //select naming pairs file

 

renParam = renList[j].split(','); //split old and new names

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2019 Jan 24, 2019

Moving this thread to the Bridge Scripting forum.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines