4 Replies Latest reply on Jan 18, 2011 3:29 AM by tansk02

    my new links


      Hi All,

      I am trying to relink my old links with my new links.

      My old link name is "EDU CH7 PG01 COL.eps"


      New link name is edu_ch7_pg01_col.eps.

      The problem is when I rename my link as "edu_ch7 pg01 col.eps" (see I change only first space to underscore), than it works fine.

      But when I replace remaining [space] with [underscore] i.e., "edu_ch7_pg01_col.eps", it won't work.

      See below code:

      var myDocLinks = app.documents[0].allGraphics;
      for (links = myDocLinks.length-1; links >= 0 ; links--)
      var myLink = myDocLinks[links].itemLink;
      var myLinkNewName = myLink.filePath.replace(/ /, "_");
      var myNewLinks = new File(myLinkNewName);
      if (myNewLinks.exists)
      try {
      catch(e) {_}

      Please let me know what is missing.

        • 1. Re: my new links
          [Jongware]-9BC6tI Level 4

          The "replace" function only works once by default, so it only replaces the first space with an underscore. Add the quantifier 'g' to change it to 'global' to make it work on the entire string:


          var myLinkNewName = myLink.filePath.replace(/ /g, "_");

          • 2. Re: my new links
            tansk02 Level 1

            Perfect. Thanks, Jongware.



            One more question, this code is not working if my links name has [solidus] character i.e., edu_s/ch7_pg01_col.eps. Could you please let me know what code is require in my script so that it relinks all the links whether it has [underscore] with [solidus].



            • 3. Re: my new links
              [Jongware]-9BC6tI Level 4

              var myLinkNewName = myLink.filePath.replace(/ /g, "_").replace(/\//g, "_");


              You should be careful using any character at all in your file names. It seems to me the forward slash is causing problems, because on the Mac it's used as a path separator. Probably either InDesign itself or Javascript tries to convert all forward and backward slashes to "the current platform", making the file name invalid.

              • 4. Re: my new links
                tansk02 Level 1

                Thanks for your  answer and valuable suggestion.