8 Replies Latest reply on Sep 22, 2016 8:11 AM by Peter Kahrel

    finding all docs with a specific link filePath

    jakec88782761 Level 1

      Hello,

       

      I'm trying to find out the name of all documents with a specific link filePath.

       

      Before I run this script I need to know that nothing bad is going to happen, so please can someone give me some advice?

       

      var myFolder = Folder ("A:\Work in progress/Jake/Indd Files/");
      var myDocs=[];
      var myFiles = myFolder.getFiles("*");

      for (i=0;i<myFiles.length;i++){
         
          $.writeln(myFiles[i].displayName);
         var doc =  myFiles[i].open();
         var docLinks = doc.links;
         for (j=0;j<docLinks.length;j++){
             if (docLinks[i].filePath="A:\Work in progress\Jake\Image Links\Aqualimb 100kg\Aqua Limb.eps"){
                 myDocs.push(doc.name)
                 }
             doc.close();
          }

        • 1. Re: finding all docs with a specific link filePath
          Peter Kahrel Adobe Community Professional & MVP

          Folder ("A:\Work in progress/Jake/Indd Files/");

           

          is not going to work, because \W will be interpreted as a control character. Use either of these two:

           

          Folder ("A:\\Work in progress\\Jake\\Indd Files\\");

          Folder ("/A/Work in progress/Jake/Indd Files/");

           

          myFolder.getFiles("*");

           

          might not work either. Use myFolder.getFiles("*.*");

           

          And links have a name, which is the graphic's name, so you could do something like this:

           

          if (docLinks[i].name === 'Aqua Limb.eps')

           

          And mind your =s: docLinks[i].filePath = "..." tries to set the file path, which is not possible anyway, so your script would break on that (I guess).

           

          Peter

          1 person found this helpful
          • 2. Re: finding all docs with a specific link filePath
            jakec88782761 Level 1

            It finds the folder fine as it is, as the console logs them all.

            I changed the docLinks to var docLinks = doc.links.everyItem(); as I realise you have to loop through a collection/array.

            I get an error on the bolded line saying that it's undefined.

             

             

            var myFolder = Folder ("A:\Work in progress/Jake/Indd Files/");
            var myDocs=[];
            var myFiles = myFolder.getFiles("*");

            for (i=0;i<myFiles.length;i++){
               
                $.writeln(myFiles[i].displayName);
               var doc =  myFiles[i].open();
               var docLinks = doc.links.everyItem();
               for (j=0;j<docLinks.length;j++){
                   if (docLinks[i].filePath="A:\Work in progress\Jake\Image Links\Aqualimb 100kg\Aqua Limb.eps"){
                       myDocs.push(doc.name)
                       }
                   doc.close();
                }

            • 3. Re: finding all docs with a specific link filePath
              Peter Kahrel Adobe Community Professional & MVP

              Use either of these, not what you had:

               

              var docLinks = doc.links.everyItem().getElements();

              or

              var docLinks = doc.links;

               

              And if (docLinks[i].filePath="A:\Wor. . . is wrong: use ===, not =

              • 4. Re: finding all docs with a specific link filePath
                tpk1982 Level 4

                try this

                 

                var myFolder = Folder ("A:\Work in progress/Jake/Indd Files/");
                var myDocs=[];
                var myFiles = myFolder.getFiles("*.*");
                for (i=0;i<myFiles.length;i++){
                    app.open(myFiles[i]);
                    var doc=app.activeDocument;
                    var docLinks = doc.allGraphics;
                    if (docLinks[i].itemLink.filePath=="A:\Work in progress\Jake\Image Links\Aqualimb 100kg\Aqua Limb.eps"){
                          myDocs.push(doc.name)
                    }
                      app.activeDocument.close();
                }
                alert(myDocs.join("\r"))
                
                • 5. Re: finding all docs with a specific link filePath
                  jakec88782761 Level 1

                  Thanks for your reply.

                   

                  I wasn't accessing the open document correctly.

                  This doesn't throw any errors but the alert is always empty and nothing appears to open during the loop.

                   

                  var myFolder = Folder ("A:\Work in progress/Jake/Indd Files/");
                  var myDocs=[];
                  var myFiles = myFolder.getFiles("*");

                  for (i=0;i<myFiles.length;i++){
                     
                      $.writeln(myFiles[i].displayName);
                     var doc =  myFiles[i].open();
                     var docLinks =app.activeDocument.links.everyItem().getElements();
                     var activeDoc = app.activeDocument;
                     for (j=0;j<docLinks.length;j++){
                         if (docLinks[i].filePath==="A:\Work in progress\Jake\Image Links\Aqualimb 100kg\Aqua Limb.eps"){
                             myDocs.push(activeDoc.name, "\r")
                              doc.close();
                             }
                       
                      }
                  }
                  alert(myDocs);

                  • 6. Re: finding all docs with a specific link filePath
                    jakec88782761 Level 1

                    Hello, this looks way better than mine.

                     

                    I ran it and it works, but there is a problem with this loop:

                     

                    if (docLinks[i].itemLink.filePath=="A:\Work in progress\Jake\Image Links\Aqualimb 100kg\Aqua Limb.eps")

                     

                    It gets to a certain document and then says null is not an object.

                    • 7. Re: finding all docs with a specific link filePath
                      jakec88782761 Level 1

                      This works up until a certain point but then return object is not valid for this line :

                       

                      if (docLinks[i].name==="Aqua Limb.eps")

                       

                      It runs fine for like 10 documents then throws this error on the same document each time.

                       

                      var myFolder = Folder ("A:\Work in progress/Jake/Indd Files/"); 

                      var myDocs=[]; 

                      var myFiles = myFolder.getFiles("*.*"); 

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

                          app.open(myFiles[i]); 

                          var doc=app.activeDocument; 

                          var docLinks = doc.links; 

                         if (docLinks[i].name==="Aqua Limb.eps"){ 

                             myDocs.push(doc.name) 

                             $.writeln(myDocs);

                          } 

                            app.activeDocument.close(); 

                      alert(myDocs.join("\r"))

                      • 8. Re: finding all docs with a specific link filePath
                        Peter Kahrel Adobe Community Professional & MVP

                        i keeps track of the documents, not the links. You need a separate counter for the links, somethin like

                         

                        var docLinks = doc.links;
                        for (j = 0; j < docLinks.length; j++) {
                          if (docLinks[j].name==="Aqua Limb.eps") {
                              // . . .
                          }
                        }
                        

                         

                        Peter