3 Replies Latest reply on Dec 23, 2016 9:00 AM by tpk1982

    Get the missing links from server

    tpk1982 Level 4

      Hi,

       

      I need to find the missing links in the server if anything present with the same image name.

       

      Step 1: Get the missing link name

      Screen Shot 2016-12-22 at 4.54.20 PM.png

       

      Step 2: Choose the main folder (for now i used Test_Images) to search the image. We need to search in the subfolders too

      Screen Shot 2016-12-22 at 4.55.43 PM.png

       

      Step 3: Copy the found image to Recovered Missing Link folder (created a folder where active document )

      Screen Shot 2016-12-22 at 4.55.31 PM.png

       

      I got some help useful threads in the forum (Re: need to relink missing links to files with extensions ). Thank you [Jongware] .But those are useful to link the images. I need to collect the images and copy in a particular folder.

       

      The below coding not copy the images.

       

      var i, j, searchfolder, movefolder=[];  
      for (j=0; j<app.documents.length; j++) {  
          doc = app.documents[j];  
        
          imgs = doc.links;  
          path = doc.filePath;  
        
          searchfolder = searchfolder || new Folder(path);  
          searchfolder = searchfolder.selectDlg(  
          "Find a path to "+doc.name+"'s images. Should contain "+  
              imgs[0].name+".*");  
        
          for (i=0; i<imgs.length; i++)  
          {  
      
              if (imgs[i].status == LinkStatus.LINK_MISSING)  
              {  
      
      
                  imglist = findAnyFileDownThere(imgs[i].name, searchfolder);  
                  if (imglist.length == 1)  
                  {  
           
                          movefolder.push( Folder(path + "/Recovered Missing Link/").getFiles() ); 
      
      
                  }  
              }  
          }  
      }  
      function findAnyFileDownThere (filename, path)  
      {  
      var result, folderList, fl;  
      result = Folder(path).getFiles (filename+".*");  
      if (result.length > 0)  
        return result;  
      folderList = Folder(path).getFiles(function(item) { return item instanceof Folder && !item.hidden; });  
        
      for (fl=0; fl<folderList.length; fl++)  
      {  
        result = findAnyFileDownThere (filename, path+"/"+folderList[fl].name);  
        if (result.length > 0)  
         return result;  
      }  
      return [];  
      }  
      

       

       

      Please help to solve this.

       

      Advance thanks,

      K

        • 1. Re: Get the missing links from server
          tpk1982 Level 4

          Hi All,

           

          I hope everyone is in holiday mood. Any suggestion helpful to complete my task

           

          Happy Christmas and New year wishes to all

          • 2. Re: Get the missing links from server
            Jump_Over Level 5

            Hi,

             

            Hm..., to copy I suggest to use method File.copy()

            ...and to relink - method Link.relink()

            var
              i, j,
              doc, imgs, path, cName, cFile,
              imglist, searchfolder, movefolder;   
            for (j=0; j<app.documents.length; j++) {   
                doc = app.documents[j];   
                imgs = doc.links;   
                path = doc.filePath;   
                searchfolder = searchfolder || new Folder(path);   
                searchfolder = searchfolder.selectDlg(   
                "Find a path to "+doc.name+"'s images. Should contain "+   
                    imgs[0].name+".*");   
               
                for (i=0; i<imgs.length; i++)   
                {   
            
                    if (imgs[i].status == LinkStatus.LINK_MISSING)   
                    {   
            
                        cName = imgs[i].name;
                        imglist = findAnyFileDownThere(cName, searchfolder);   
                        if (imglist.length == 1)   
                        {   
                             movefolder = Folder(path + "/Recovered Missing Link"); 
                             if (!movefolder.exists) movefolder.create();
                             cName = imglist[0].name;
                             cFile = File(movefolder + "/"+ cName);
                             if (!cFile.exists) imglist[0].copy(cFile);
                             imgs[i].relink(cFile);
                        }   
                    }   
                }   
            }   
            function findAnyFileDownThere (filename, path)   
            {   
            var result, folderList, fl;   
            result = Folder(path).getFiles (filename);   
            if (result.length > 0)   
              return result;   
            folderList = Folder(path).getFiles(function(item) { return item instanceof Folder && !item.hidden; });   
               
            for (fl=0; fl<folderList.length; fl++)   
            {   
              result = findAnyFileDownThere (filename, path+"/"+folderList[fl].name);   
              if (result.length > 0)   
              return result;   
            }   
            return [];   
            }
            

             

            Keeping Best Wishes for all these days

             

            Jarek

            • 3. Re: Get the missing links from server
              tpk1982 Level 4

              Hi Jarek,

               

              Working superbly. Thank you so much.

               

              Have a great weekend.

               

              Thanks,

              K