9 Replies Latest reply on Jul 17, 2014 6:46 AM by Dapeamel

    active path and function

    Dapeamel Level 1

      Hello all good Adobe Members!

       

      I have wrote a function in a script called "interface.jsx"

      Our project and folderstructure is always the same.

      my "interface.jsx" is saved in "/kommuni/LaRe/LareAUTO/341542/scripts/interface/interface.jsx"

       

      here is my code for interface.jsx

       

      See code below

      function CopyStep1()
      {
        var myFolder = Folder.selectDialog ('Choose a Folder');  
        if(myFolder != null)
        {  
        var myFiles = myFolder.getFiles('*.indd');  
        for (i = 0; i < myFiles.length; i++)  
        {  
        var myFile = myFiles[i];  
        destFile1= new File("/Kommuni/LaRe/LareAUTO/341542/source/batch1/" + myFile.name);// to create an object  
        destFile2= new File("/Kommuni/LaRe/LareAUTO/Backup/341542/batch1/" + myFile.name);// to create an object  
        myFiles[i].copy (destFile1);   
        myFiles[i].copy (destFile2);
        }  
        }  
      }
      

       

       

      How do I make my script always know my folderstructure?

       

       

      I have got a Filedialog,

       

      if you see on the line 10 and 11, I have written the full paths, but I want to filter the filepath

      so my script just goes some steps up to root(341542)

       

      when I run the script it opens a dialog window and

      I want my dialog window shall be on /kommuni/LaRe/LareAUTO/341542/ as default.

       

      we know the interface is in "/kommuni/LaRe/LareAUTO/341542/scripts/interface/interface.jsx"

       

      so just go back to "/kommuni/LaRe/LareAUTO/341542/"

       

      how do I make this?

       

      Thank you in advance

       

      all Adobe Members

        • 1. Re: active path and function
          Jump_Over Level 5

          Hi,

           

          There is a method selectDlg() which is selecting predefined folder,

          so if a goal is to open dialog with a specific folder selected use:

           

          mFolder = Folder("/kommuni/LaRe/LareAUTO/341542/");
          mFolder = mFolder.selectDlg();
          

           

          Notice that predefined folder is selected not opened...

          Jarek

          • 2. Re: active path and function
            Dapeamel Level 1

            well it works.

             

            but this is not really what I was searching for indeed,

            cause we have defined the whole path,

            that should better if we could just go some levels up from the interface.jsx (cause that is the scriptfile we are running)

            because we have like hundreds of jobs. example (341542,34153,341543 etc)

             

            I dont want to each time there is a new job go and modify the jobnumber in the script

             

            have you got a good  solution on this sir?

             

            Thank you so much in advance sir

            • 3. Re: active path and function
              Jump_Over Level 5

              Dapeamel wrote:

               

              ...

              I have wrote a function in a script called "interface.jsx"

              ...

               

              According to above you are looking for help not a "ready-steady" code, I think.

              I don't have a solution written already. Have idea how to do it and can help you if you got some questions.

              I.e. it could work like this:

              • active script path is app.activeScript.fsName
              • you can .split("/") this path and get an array as long as many "/" found inside the string;
              • you can .splice(startElement, howManyToRemove) an array with proper number of elements (remove some)
              • you can .join("/") an array with parameter "/" to take a desired path as a result

               

              Jarek

              • 4. Re: active path and function
                Dapeamel Level 1

                woha it's way to complicated to me haaha

                I have no clue how to use the code you sent me I am total new to indd javascript haaha

                 

                I have all questions in the world

                • 5. Re: Re: active path and function
                  pixxxel schubser Level 5

                  Hi Dapeamel,

                  try something like this:

                   

                  // save this in scripts folder and run
                  // regards pixxxelschubser
                  alert(File($.fileName).fullName);
                  alert(File($.fileName).parent.fullName);
                  alert(File($.fileName).parent.parent.fullName);
                  alert(File($.fileName).parent.parent.parent.fullName);
                  
                  

                   

                  Have fun

                   

                  • 6. Re: Re: Re: active path and function
                    Dapeamel Level 1

                    Hi mate

                     

                    Thank you something like that how do I integrate that in my function?

                    hmm..

                     

                    function CopyStep1()
                    {
                    
                    mFolder = Folder("/kommuni/LaRe/LareAUTO/341542/");
                    
                    
                    mFolder = mFolder.selectDlg();
                      if(mFolder != null)
                      {  
                      var myFiles = mFolder.getFiles('*.indd');  
                      for (i = 0; i < myFiles.length; i++)  
                      {  
                      var myFile = myFiles[i];  
                      destFile1= new File("/Kommuni/LaRe/LareAUTO/341542/" + myFile.name);// to create an object  
                      destFile2= new File("/Kommuni/LaRe/LareAUTO/341542/ARKIV/" + myFile.name);// to create an object  
                      myFiles[i].copy (destFile1);   
                      myFiles[i].copy (destFile2);
                      }  
                      }  
                    }
                    

                     

                    Thank you so much so far pixxelschubser

                    • 7. Re: Re: Re: Re: active path and function
                      Chinnadk Level 4

                      Hi,

                       

                      Use the below script.

                      1. It will copy all the indesign files from the folder /kommuni/LaRe/LareAUTO/ + JobID(this JobID you should select via selectDlg()) to /kommuni/LaRe/LareAUTO/JobID/batch1.
                      2. It will create a folder with a name of jobID under the kommuni\LaRe\Backup and copy all the files.

                       

                      CopyStep1();
                      function CopyStep1()  
                      {  
                      mFolder = Folder("/kommuni/LaRe/LareAUTO/");//root folder
                      var mFolder = mFolder.selectDlg();//select the job id
                      var jobID = mFolder.toString().replace(mFolder.parent.toString() + "/","");
                      var jobidInBackup = new Folder(mFolder.parent.parent + "/Backup/" +"/"+ jobID);
                      var backuppath = jobidInBackup.create();//to create a jobid folder in backup folder.
                      if(mFolder != null)  
                      {    
                              var myFiles = mFolder.getFiles('*.indd'); 
                              for (i = 0; i < myFiles.length; i++)    
                              {    
                                      var myFile = myFiles[i];
                                      destFile1= new File(mFolder.parent + "/"+jobID +"/batch1/" +  myFile.name);// to create an object 
                                      destFile2= new File(mFolder.parent.parent +"/Backup/"+jobID+"/"+myFile.name);// to create an object    
                                      myFiles[i].copy (destFile1);     
                                      myFiles[i].copy (destFile2);  
                                  }    
                              }    
                          } 
                      

                       

                      Regards,

                      Chinna

                      • 8. Re: active path and function
                        Dapeamel Level 1

                        Wonderful!

                         

                        I will come back with results thanks so much in advance

                         

                        Chinnadk

                        • 9. Re: active path and function
                          Dapeamel Level 1

                          I think your code is almost perfect,

                           

                          I got a problem tho,

                           

                          in the code above you have defined that you create batch1,

                          this will not work because each time I pick new INDD files, the script creates batch1 again and again,

                           

                          it would be better if instead of "batch1"

                          the script would look one level up for the folder name  example "batch3" then takes that name and create the folder.

                           

                           

                          Could you master form the code that way?

                           

                          Thank you in advance sir Chinna!