Skip to main content
New Participant
May 17, 2013
Question

add rating to file name

  • May 17, 2013
  • 1 reply
  • 519 views

I need to strip the last instance of an underscore and the text that follows and replace with underscore and the rating (3).

1111_11_111_012 becomes

1111_11_111_3

thanks

This topic has been closed for replies.

1 reply

Inspiring
May 17, 2013

I think a little more info is needed… This works here on a bunch of my *.ai files…

Is whats behind the last underscore always digits like your example…?

What file extensions do you need to deal with…?

Im sure a better expression could be used…

#target bridge

renameSelectedFiles();

function renameSelectedFiles() {

   

    var i, count, doc, file, rate, oldName, newName;

   

    doc = app.document;

   

    count = doc.selectionsLength;

   

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

       

        rate = doc.selections.rating;

       

        oldName = decodeURI( doc.selections.spec.name );

       

        newName = oldName.replace( /_.+\.ai$/i, '_' + rate + '.ai' ); // I already know the extension

       

        doc.selections.spec.rename( newName );

       

    };

   

};

New Participant
May 18, 2013

There is always a _ before the text that needs to be changed. but the format before changes. The files are tiff or jpeg.

Your script works but seems to always rename the first file as well and removes the rating for the renamed image?

Thanks