1 Reply Latest reply on Apr 25, 2014 6:06 PM by RobertKyle

    Linked Image file path cleanup

    BradRE

      Regex frustrates me, especially with trying to work with slashes... I just haven't got it yet. I'm looking just for a code snippet to thrown in another clean up script I use. To standardize to UNC, as some templates were created on workstaions (also Mac vs PC) that were incositently mapped (i.e. W:/ or X:/ etc.). Blown a day messing with this so far, maybe reaching out for help would work... Thanks in advanced!

       

      var gDoc = app.activeDocument;

      var gLinks = gDoc.links;

      var gCounter = 0;

       

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

                var currentLink = gLinks[i];

                var oldPath = currentLink.filePath;

                oldPath = oldPath.replace(/:|\\/g, "\/");

       

      // Intention

      // IF the drive letter W:/ or X:/ is used

      // IF case is \\OHFILE02\Personalization\

      // THEN

      // REPLACE with \\ohfile02\Personalization\ (string replace: would be case sensitive, not just all to lowerCase)

      // ALSO above would be for all linked images as it looks like it's looping through currentLink, is that correct?

       

      Thanks again!

        • 1. Re: Linked Image file path cleanup
          RobertKyle Level 2

          I don' t pretend to know all the ins and outs of this, but I've beat my head on the same wall to know that you have to use two slashes to find or replace one. In other words:

           

          \\ = "\"

          \/  = "/"

          \\\\ = "\\"

           

          I also know that you can use "/i" in the first part of the replace statement to make it case insensitive. "/gi" makes it global and case insenstive so:

           

          oldpath.replace(/\\\\ohfile02\\Personalization\\/gi,"whatever")

           

          should catch all variations of upper and lowercase, so you end up with "whatever\Personalization\"

           

          As for the replace string, I think that what you type is what you get.