10 Replies Latest reply on Jul 22, 2013 3:03 AM by rajnikids

    Replace existing files.

    rajnikids

      Hi Forum, using the below code, im copying the links to the particular folder.

       

      The problem is when i'm copying Links to the particular folder and if the particular folder already has the same links (file name matching).

       

      The file  is copied as _1 instead of replacing directly.

       

      var theLinks = app.documents[0].links;

      myserver = Folder("/Users/rajni/Desktop/TestLink");

      //ky = myserver.path + "/" + myserver.name;

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

      {

      theLinks[i].copyLink(myserver);

      }

       

      I do want to copy the links from the link path and replace to the Particular folder (if the particular folder already has the same link).

       

      Forum!!! Any help on this.

        • 1. Re: Replace existing files.
          rajnikids Level 1

          Hi Forum,

           

          I have used another way of copying Links files, which is seen in indesign Link panel.

           

          Copied all the linked files.

           

          But, I can't able to open files, it says it been damaged.

           

           

          var theLinks = app.documents[0].links;

          myserver = Folder("/Users/wleastudio/Desktop/TestLink");

           

          ky = myserver.path + "/" + myserver.name;

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

          {

              currentPath = Folder(File(theLinks[i].filePath).path).getFiles("*");

          var myResult = currentPath[i].copy(ky +"/"+theLinks[i].name);

           

          }

           

          Any help please.

          • 2. Re: Replace existing files.
            rajnikids Level 1

            Sorry my second post is wrong.

             

            I just replaces the files found inside the link path and rename the link name to some other document.

             

            and so the problem is.

             

            Can, i have the solution for my first post. please.

            • 3. Re: Replace existing files.
              rajnikids Level 1

              Well!,

               

              How do i add the below piesces in my first blog to replace existing files.

               

              Files.copy(Paths.get(tempFileName),Paths.get(fileName),
                
              StandardCopyOption.COPY_ATTRIBUTES,StandardCopyOption.REPLACE_EXISTING);

               

              thanks in advance.

              • 4. Re: Replace existing files.
                rajnikids Level 1

                Hi Forum.

                 

                Acutally Im trying to use the indesign options "CopyLinksTo" in Link panel,

                 

                But while im trying to copy the files to the particular location. the  _1 is added at end of the each links names.

                 

                eg. 123_abc.jpg is renamed as, 123_abc_1.jpg. //here _1 is added at each and evey time, when running the script.... _1, _1_1, _1_1_1 etc., like this.

                 

                That where my problem is.

                 

                Please help me to replace the links while copying to the other location (if the same link with the same name already resides inside).

                 

                Many thanks

                • 5. Re: Replace existing files.
                  rajnikids Level 1

                  OK,

                   

                  NOw I got the way to replace but the result is" Files already exists.

                   

                   

                  var theLinks = app.documents[0].links;

                  myserver = Folder("/Users/rajni/Desktop/TestLink");

                  //ky = myserver.path + "/" + myserver.name;

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

                  {

                  theLinks[i].copyLink(myserver +"/" + links[i].name);     // here it says" files already exists. Please help here...... HOw do i make it to replace, if found.

                  }

                  • 6. Re: Replace existing files.
                    Jump_Over Level 5

                    Hi,

                     

                    try this:

                     

                    var destFolder = "~/Desktop/test/",
                    mDoc = app.activeDocument,
                    k, currLink, currFile, currName, destFile;
                    
                    if(!Folder(destFolder).exists) 
                         Folder(destFolder).create();
                    
                    for (k = 0 ; k < mDoc.links.length; k++) {
                         currLink = mDoc.links[k];
                         currFile = File(currLink.filePath);
                         currName = currFile.name;
                         destFile = File(destFolder + currName);
                         currFile.copy(destFile);
                         }
                    

                     

                    Jarek

                    • 7. Re: Replace existing files.
                      rajnikids Level 1

                      Hi Jarek!!!,

                       

                      Really thanks for your stuff here..

                       

                      And I'm trying to save the links into a subFolder of each MainFolder.

                       

                      eg. Desktop/ABC/File1/IndesignDoc (a folder where indesign is saved)

                       

                      and

                      Desktop/ABC/File1/LinksFolder (a folder where links are to be saved)...

                       

                      so instead of var destFolder = "~/Desktop/test/", how can i assign Linksfolder inside ABC/File1.

                       

                      ALso, the Main folder of the indesign files and links folders' will be changing... like below

                      Desktop/ABC/File2/IndesignDoc...

                      Desktop/ABC/File3/IndesignDoc

                       

                      Desktop/ABC/File2/LinksFolder...

                      Desktop/ABC/File3/LinksFolder..

                       

                      thanks a tonne.

                      • 8. Re: Replace existing files.
                        rajnikids Level 1

                        Hi Jarek!!!

                         

                        Attached snapshot for clearance...

                         

                        Screen Shot 2013-07-22 at 10.44.56.png

                        • 9. Re: Replace existing files.
                          Jump_Over Level 5

                          Hi,

                           

                          modify var declaration:

                           

                          var mDoc = app.activeDocument,
                          destFolder = Folder(mDoc.filePath).parent + "/LINKS DOC/",
                          k, currLink, currFile, currName, destFile;
                          
                          if(!Folder(destFolder).exists) 
                               Folder(destFolder).create();
                          
                          for (k = 0 ; k < mDoc.links.length; k++) {
                               currLink = mDoc.links[k];
                               currFile = File(currLink.filePath);
                               currName = currFile.name;
                               destFile = File(destFolder + currName);
                               currFile.copy(destFile);
                               }
                          

                           

                          Jarek

                          • 10. Re: Replace existing files.
                            rajnikids Level 1

                            Thanks you Jarek!!!

                             

                            I have been trying like this.

                             

                            destFolder = app.activeDocument.filePath + "LINKS DOC",

                             

                            and found the file name has been renamed......

                             

                            thanks so much for your special attention on my request.

                             

                            Many thanks... God bless U...