Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 );
};
};
Copy link to clipboard
Copied
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