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

Editing a current filename to add a suffix in InDesign

New Here ,
Aug 09, 2015 Aug 09, 2015

Hi there!

I have been searching through the forums trying to find something that would help me edit file names so that they include a suffix at the end. I did find some scripts that have gotten me to a point where I can rename the file with the shortname (var myPrepend), have it add a number, and then have it add the language suffix. However, I would like to keep the name of the original file and just add the language suffix if possible. The code below does help if I want to rename files completely but I would also like an option that will literally just add "_es" or "_fr" and others.

In addition to that, I would like to specifically target EPS and or ILLUSTRATOR files ONLY. I do not want to change the names of tiffs, jpegs, or anything else.

Is this at all possible? Thank you in advance!

Here is what I have so far:

var myDoc = app.activeDocument;

var myPrepend = prompt("Please enter issue shortname.\nExample: Client_Project", "Issue Shortname");

if (!myPrepend) exit();

var myLanguage = prompt ("Please enter language suffix.\nExample: _es (Spanish)", "Enter language suffix");

if (!myLanguage) exit();

var response = confirm("Warning: You are about to rename all images linked to the foremost Indesign Document - proceed?\n Keep in mind - it is not reversible!", false, "Rename Links Script");

if (!response) exit();

var doc = app.activeDocument,

    links = doc.allGraphics, count = 1, eqcount = 1, a = "000" ;

for(var i=links.length-1;i>=0;i--)

{

                var ext = links.itemLink.name.substr(links.itemLink.name.lastIndexOf(".")),

                    old = File(links.itemLink.filePath),

                    num = (count++).toString(),

                    newname = myPrepend + a.substring(0, a.length - num.length) + num + '_' + myLanguage + ext

                old.rename(newname);

                links.itemLink.relink(File(old.toString().replace(links.itemLink.name,newname)))

    }

TOPICS
Scripting
747
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
Advisor ,
Aug 10, 2015 Aug 10, 2015

var fname=links.itemLink.filePath;

ext = fname.substr(fname.lastIndexOf(".")),

base=fname.substring(0,fname.lastIndexOf(".")),

old = File(links.itemLink.filePath),

num = (count++).toString(),

newname = myPrepend + base+a.substring(0, a.length - num.length) + num + '_' + myLanguage + ext;

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 ,
Aug 10, 2015 Aug 10, 2015

Thanks for responding so quickly Vamitul! I am just not clear on what exactly I should be replacing, taking out, and what I should be leaving.

And would you happen to know how I would be able to apply it only to eps files?

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
Advisor ,
Aug 10, 2015 Aug 10, 2015
LATEST

In your last "for" block, replace your var block with mine.

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