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

add rating to file name

New Here ,
May 17, 2013 May 17, 2013

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

TOPICS
Scripting
470
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
Guru ,
May 17, 2013 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 );

       

    };

   

};

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 17, 2013 May 17, 2013
LATEST

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

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