4 Replies Latest reply on Jul 14, 2016 12:54 PM by Jump_Over

    I need help with a script to search for missing links on my computer and then relink them.

    Awitmer Level 1

      Hello everybody!

       

      Recently my IT department at my workplace moved a bunch of files, so I

      literally have hundreds .indd files with missing links. I a script that

      could search the directory for the missing links and then relink them, would

      be really nice to have!

       

      I found the script below in this forum to find and relink missing links but

      it is not working for me. Below is a screenshot of the message I get when

      the script is finished running. I know the file is in the directory I choose

      because I can find it in Windows explorer. What am I missing?

       

      Can anybody help me out? I am using Indesign CS6 on a Windows 7 machine. Let

      me know if you need any more info from me.

       

      Here is the code for the script that I am trying to use.

       

      //Search computer for missing links.

       

      var processed = 0

      var skipped = 0

      var updated = 0

      if (app.documents.length > 0){

          if(app.activeDocument.links.length > 0){

              var mydoc = app.activeDocument;

              var mylinks = mydoc.links;

              var myRoot = Folder.selectDialog("Choose the volume or server where

      assets are located", undefined, false);

              main();

      }

      else

      { alert("No Links present")

          }

      }

      else{alert("No Documents Open")

          }

      function main(){

          if(myRoot != null){

              for(var i = 0; i < mylinks.length ; i++){

                  if(mylinks.item(i).status == LinkStatus.linkMissing){

                          var linkdata= mylinks.item(i).filePath;

                          var my_result = linkRepair(linkdata);

                              if (my_result == false){

                                  var filetype = "." + mylinks.item(i).linkType;

                                  var mysearch =  search(linkdata, filetype);

                                      if(mysearch != undefined){

      var myswitch = confirm(mylinks.item(i).name + " has been found in a

      different location, Relink and Update?", "Relinker")

                                              if(myswitch){

      mylinks.item(i).relink(File(mysearch));

                                                  mylinks.item(i).update();

                                              }

                                          }

                                  else{

                                      alert("" + mylinks.item(i).name +" was not

      found\nFolders processed: "+processed + "\nFiles skipped: "+ skipped)

                                  }

                              }

                              else{ alert( my_result + " has been found");

                                  mylinks.item(i).relink(File(my_result));

                      }

                  }

              }

          }

      }

      function linkRepair(linkdata){

      var mypath = linkdata.split(":")

              my_status = analyzePath(mypath)

              if(my_status == true){alert("UPDATED");

                      updated++    

                  }

          return my_status

          }

      function analyzePath(mypath){

      var num = mypath.length ;

      for(var i = 0; i < num-1; i++){

          mypath.shift()

          var newpath = pathRebuild(mypath)

          newpath = (myRoot + newpath)

              if(File(newpath).exists){

                  return newpath

                  }

              }

          return false

      }

      function pathRebuild(pathArray){

      var solidPath = ""

          for(var i = 0; i < pathArray.length ; i++){

              solidPath +=  "/" + pathArray[i] ;

          }

          return solidPath;

      }

      function search(linkdata, filetype){

          var mypath = linkdata.split(":")

          var mylink = mypath.pop();

          var OK = confirm("Relative Path does not exist, search folder hiearchy

      for file?", true, "File Scanner")

          if(OK){

      var myscanresult = getfiles(mylink, myRoot)

      return myscanresult

      }

          }

      function getfiles(mylink, myBase){

      myBase = Folder(myBase);

      var files = myBase.getFiles("*")

      for(var i = 0; i < files.length; i++){

      try{

      var foldertest = files[i].getFiles();

      processed++

      var myfile =    File(files[i] + "/" + mylink)

          if(myfile.exists == true){

              return myfile

              break;

              }

          else{

          var myscan = getfiles(mylink, Folder(files[i]))

              if(myscan != undefined){

              return myscan

              break;

              }

          }

      }

      catch(myerror){

          skipped++

              }

          }

      }

      Thanks in advance for your help!!!! I greatly appreciate it!!!