6 Replies Latest reply on Mar 29, 2014 2:04 AM by Sudha K

    Match file name

    Sudha K Level 1

      Hi,

       

         Im matching the images from InDesign to folder and copying that images to another place.  When im doing, Its ("Sample_©_Black.eps") not matching with the image names with the folder.

       

        The folder contains this image but dono why its not matching. 

       

       

      Thanks in advance,

      Sudha K

        • 1. Re: Match file name
          Jump_Over Level 5

          Hi,

           

          paste a code with your matching way

           

          Jarek

          • 2. Re: Match file name
            Sudha K Level 1

            Hi,

             

              Im using the below code.

             

               imageProcess(myDoc, imageFiles,imageNames);               //     imageNames - File names from folder

             

             

            function imageProcess(myDoc1, imageFiles1,imageNames1)

            {

                var lnkName ="";

                var copyPath = "";

                var copyFolder = ""

                 var lnkName = "", lnkName1 = "";

                var docImgsNames = "#";

               

                if(myDoc1.links.length > 0)

                {

                    myDoc1Lnks = myDoc1.links;

                    allImagesStr = "#"+imageNames1.join("#")+"#";

                   

                    for(var lCnt = 0; lCnt < myDoc1Lnks.length; lCnt++)

                    {

                        lnkName = ""           

                        try{

                            lnkName = myDoc1Lnks[lCnt].name  

                            lnkName = decodeURI(lnkName);

                            lnkName1 =  replaceStr(lnkName)

                         }catch(e){

                            lnkName = "";  

                        }             

                       

                        if(lnkName1.length > 0 && allImagesStr.match("#"+lnkName1+"#") != null)

                        {               

                            var nameIdx = returnIndx(imageNames1, lnkName)

                            if(nameIdx != null)

                            {

                                var curImgObj = imageFiles1[nameIdx];   

                                if(curImgObj.exists)

                                {  

                                    if( File(copyPath).exists == false)

                                    {

                                        copyFolder = Folder(copyPath);

                                        copyFolder.create();

                                    }

                               

                                    curImgObj.copy(File(copyPath+"/"+lnkName));

                               

                                }else{ //Image Not exists

                                }

                           

                            }else{   // Image Not found

                            }

                        }else           // Image Not found

                        {

                        }

                   

                        docImgsNames += lnkName +"#";

                    }

                   

                }   

            }

             

            function replaceStr(fndCont)

            {

                var newWord = "";

                for(var cCnt = 0; cCnt < fndCont.length; cCnt++)

                {

                    var cChar = fndCont[cCnt];

             

                    if(cChar.match(/[^0-9a-zA-Z]/))             

                    {

                        cChar = "\\"+cChar;

                    }

                    newWord +=cChar;

                }      

             

                return newWord;

            }

            • 3. Re: Match file name
              Jump_Over Level 5

              Hi,

               

              In your code - did you check if copyFolder.create() == true?

               

              If your goal is to copy all graphic's linked files into a chosen folder ==>

              I suggest another way:

               

              var 
                  mDoc = app.activeDocument,
                  copyPath = mDoc.filePath,
                  copyFolder = Folder(copyPath + "/Images"),
                  mLinks, curLink, curFile, curName, k;
              
                  if ( copyFolder.create() ) {
                      mLinks = mDoc.links.everyItem().getElements();
                      for (k = 0; k < mLinks.length; k++) {
                          curLink = mLinks[k];
                          curFile = File(curLink.filePath);
                          if (curFile.exists) {
                                  curName = curFile.displayName;
                                  curFile.copy(copyFolder.fullName + "/" + curName);
                              }
                          else {} // file doesn't exist
                          }
                      }
                  else {} // can not create a folder
              

               

              copyFolder is a subfolder "Images" of document parent

               

              Jarek

              • 4. Re: Match file name
                Sudha K Level 1

                Hi,

                 

                 

                   I need to copy the link images from chosen path to indesign file path if the link images are there in chosen folder.

                • 5. Re: Match file name
                  Jump_Over Level 5

                  Hi,

                   

                  If we talk about your code:

                  1. your copyPath is always empty string so, at least in Windows, copyFolder can not be created

                  2. your replaceStr() function returns - i.e. - "/$" from "$" and I am not sure is it a goal..., unless your idea was to match regEx instead of string...

                  3. function returnIndx() is missed

                   

                  If we talk about a goal:

                  1. Are you going to clean up doc links? I mean graphics are linked to various location and need to be moved to just one? And relink?

                  2. Are you going to fix links? I mean links are broken and code should compare contents of chosen folder (folders), match filePath, copy file and relink?

                   

                  Jarek

                  • 6. Re: Match file name
                    Sudha K Level 1

                    Hi,

                     

                     

                      I need to copy the link Images from download path to working path (INDD File Image Folder). Im not relink the images just copying from one path to another path by matching Image name.

                     

                    When matching link image name ("Sample_©_Black.eps") with folder images, its not matching. If its matched, will copy into Images folder. When doing this, the image name ("Sample_©_Black.eps") is not matching. Dono why?? So tat I used replaceStr to replace special characters with "\" and match. 

                     

                    copyPath -  Image Folder Path

                     

                    returnIndx - To get index of an array (Image file) based on image name.

                     

                     

                     

                    function returnIndx(fArr, fVal)

                    {

                        var res = null;

                        var fStr = "#"+fArr.join("#")+"#";

                       

                        try{

                            if(fStr.match(fVal) != null)

                            {

                                var sArr = fStr.split("#"+fVal+"#");       

                                var sArr1 = sArr[0].split("#");       

                                return sArr1.length-1;       

                            }

                        }catch(e){return null}

                    }