Skip to main content
TradewindCreative
Participant
August 23, 2013
Answered

Help with batch renaming

  • August 23, 2013
  • 1 reply
  • 2088 views

I need to create a custom renaming script and just can't seem to figure it out. I'm already in Bridge CS6 with the Batch Rename dialog open.

My files are currently named as such: ABC-100-name-01

I need them to read: ABC-100-01-name

Absolutely any help is appreciated! This will be an incredible time saver.

This topic has been closed for replies.
Correct answer Muppet Mark

OK, try adding this to your scripts folder… Done slighty long hand so's you can swap about if needed…

To run select Custom Rename at the bottom of the Tools menu…

#target bridge

#engine main

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

          var toolMenu = MenuElement.find( 'Tools' ),

 

          customRename = new MenuElement( 'command', 'Custom Rename', '-at the end of toolMenu', 'muppet009' );

};

customRename.onSelect = function () { renameFiles(); }

function renameFiles() {

 

          if ( app.documents.length == 0 ) { return; }

 

          var i, count, doc, file, parts, baseName, ext, oldName, newName;

 

          doc = app.document;

 

          count  = doc.visibleThumbnailsLength;

 

          for ( i = 0; i < count; i++ ) {

 

                    if ( doc.visibleThumbnails.type == 'file' ) {

 

                              oldName = decodeURI( doc.visibleThumbnails.name );

 

                              baseName = oldName.match( /(.*)\.[^\.]+$/ )[1];

 

                              ext = oldName.replace( /^.*\./,'' );

 

                              parts = baseName.split( '-', 4 );

 

                              newName = parts[0] + '-' + parts[1] + '-' + parts[3] + '-' + parts[2];

 

                              if ( ext != '' ) { newName += '.' + ext; }

 

                              file = doc.visibleThumbnails.spec;

 

                              //$.writeln( newName );

 

                              file.rename( newName );

 

                    };

 

          };

 

};

1 reply

Muppet MarkCorrect answer
Inspiring
August 26, 2013

OK, try adding this to your scripts folder… Done slighty long hand so's you can swap about if needed…

To run select Custom Rename at the bottom of the Tools menu…

#target bridge

#engine main

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

          var toolMenu = MenuElement.find( 'Tools' ),

 

          customRename = new MenuElement( 'command', 'Custom Rename', '-at the end of toolMenu', 'muppet009' );

};

customRename.onSelect = function () { renameFiles(); }

function renameFiles() {

 

          if ( app.documents.length == 0 ) { return; }

 

          var i, count, doc, file, parts, baseName, ext, oldName, newName;

 

          doc = app.document;

 

          count  = doc.visibleThumbnailsLength;

 

          for ( i = 0; i < count; i++ ) {

 

                    if ( doc.visibleThumbnails.type == 'file' ) {

 

                              oldName = decodeURI( doc.visibleThumbnails.name );

 

                              baseName = oldName.match( /(.*)\.[^\.]+$/ )[1];

 

                              ext = oldName.replace( /^.*\./,'' );

 

                              parts = baseName.split( '-', 4 );

 

                              newName = parts[0] + '-' + parts[1] + '-' + parts[3] + '-' + parts[2];

 

                              if ( ext != '' ) { newName += '.' + ext; }

 

                              file = doc.visibleThumbnails.spec;

 

                              //$.writeln( newName );

 

                              file.rename( newName );

 

                    };

 

          };

 

};

TradewindCreative
Participant
August 26, 2013

Muppet Mark, I can't thank you enough!! Unfortunately this is my first script and I don't know what to do with this. I was trying to use the built in batch rename console before.

Inspiring
August 26, 2013

This is a bespoke solution… It don't use the batch rename dialog… If you search here you will find how to add this to the bridge app…