9 Replies Latest reply on Aug 9, 2016 3:10 AM by scriptworker

    Write last folder naming

    karthiks94217840 Level 2

      Hi Friends,

       

      I need your help!

       

      @My work (write report): I need to write last revision folder name only. Also, i was try to some code, that code is write-report for all folder name is given. But. i need to last folder names only. I have place some example screenshot below:

       

      After run my script generate the report. (Wrong Report)

       

      1.png

       

      I need report. (correct Report)

       

      2.png

       

      My code below:

       

      var Report = new File("C:/Users/karthiks/Desktop/z/Client78_Revision Report.txt" );
      Report.open("w");
      Report.writeln("Journal Name\tArticle ID\tNumber of Revision\r*********************************\r\r");
      
      
      var basePath = "C:\\Users\\karthiks\\Desktop\\z";  // Local path:
      var basePathFiles = Folder(basePath).getFiles();
      var basePathFilesLen = basePathFiles.length;
      
      
      for (var bsf = 0; bsf < basePathFilesLen; bsf ++){
                  
                  if (basePathFiles[bsf] instanceof Folder){
      
      
                      var articleFolder = Folder(basePathFiles[bsf].fullName);
                      var articleFolderSubFolders = articleFolder.getFiles();
                      var articleFolderSubFoldersLen = articleFolderSubFolders.length;
                          
                      for (var i=0; i<articleFolderSubFoldersLen; i++){
                            
                              var currFolder = articleFolderSubFolders[i];
                              var currFolderName = currFolder.name;
                                   
                              var  articleFolder2 = Folder(currFolder + '\\' + currFolder.name + '_Inputs\\');
      
      
                              var articleFolderSubFolders2 = articleFolder2.getFiles();
                              var articleFolderSubFoldersLen2 = articleFolderSubFolders2.length;
      
      
                                  for (var n=0; n<articleFolderSubFoldersLen2; n++){
                                          var currFolder2 = articleFolderSubFolders2[n];
                                          var currFolderName2 = currFolder2.name;
      //~                                            alert(currFolderName2); 
      
      
                                     if (articleFolderSubFoldersLen2 > 4){
                                         
      
      
      //***************************** something i have missing code here  *********************
                                          
                                              Report.writeln(articleFolder.name + "\t" + currFolder.name+ "\t" + currFolderName2 + "\n")                
                                      }
                                  }              
                      }
                  }
      }
      Report.close(); 
      

       

      please suggest friends.

       

       

      Thanks in Advance.

      KS

        • 1. Re: Write last folder naming
          karthiks94217840 Level 2

          HI,

           

          This my folder structure:

           

          4.png

           

          Thanks in Advance.

          KS

          • 2. Re: Write last folder naming
            scriptworker

            If you do this:

             

            var currFolder2 = articleFolderSubFolders2[articleFolderSubFolders2.length-1].toString().split('_')[0];

            var revision = articleFolderSubFolders2[articleFolderSubFolders2.length-1].toString().split('_')[1]

             

            You will have the folder and revision number.

            Is that what you are looking for?

             

            Michel

            • 3. Re: Write last folder naming
              karthiks94217840 Level 2

              Hi SW,

               

              Thanks to your replay,

               

              Is that what you are looking for?  ----> I need to collect for all latest files (project voices) total No.of project above 100.

               

              EXP: Our Folder Structure below:

               

              Project Name --> AHMT --> 108531 --> 108531_Inputs -- > 108531_Final

                                                                      108531_First Proof

                                                                      108531_R1

                                                                      108531_R2

                                                                      108531_R3

               

              That above structure R2 and before all file default structure this is no needed. But R3 and after received files i need to write report.

               

              *************************

               

              @One more question: I have add your above code in my script. That code alert(Final, First_proof, R1, R2 and R3) for one by one. But i need to alert(R3) latest folder only.

               

              Please suggest friends.

               

              Thanks in Advance

              KS

               

              • 4. Re: Write last folder naming
                karthiks94217840 Level 2

                Hi,

                 

                This structure i like this,

                 

                AA54321R4
                AHMT108531R4
                AHMT109587R3
                AHMT65820R3
                AHMT79060R2
                AMEP100660R4
                AMEP101099R3
                AMEP101395R1
                AMEP101698R2
                AMEP102000R7
                AMEP102081R2
                AMEP102111R1

                    

                Thanks

                • 5. Re: Write last folder naming
                  scriptworker Level 1

                  Did you place the code outside the for-loop?

                  I think you do not need the last for-loop.

                   

                  Michel

                  • 6. Re: Write last folder naming
                    karthiks94217840 Level 2

                    Hi SW,

                     

                    Thanks to your replay,

                     

                    I have used your second code. That code i have modified one number only, after that working good.

                     

                    Modified code:

                     

                    var revision = articleFolderSubFolders2[articleFolderSubFoldersLen2-1].toString().split('_')[2] // change 1 to 2.

                     

                    @One more thing: Some of the project i have received above 14 files "R14". But, Here with alert for only "R9" this code counsel for "R9" is last folder, but 14 folder is there). I have place screenshot for your reference.

                     

                    Example:

                     

                    3.png

                     

                    I need to alert for last folder name R14. Please suggest friend

                     

                    My code also below:

                     

                    **********************************

                    var Report = new File("C:/Users/karthiks/Desktop/z/Client78_Revision Report.txt" ); 

                    Report.open("w"); 

                    Report.writeln("Journal Name\tArticle ID\tNumber of Revision\r*********************************\r\r"); 

                     

                    var basePath = "C:\\Users\\karthiks\\Desktop\\z";  // Local path: 

                    var basePathFiles = Folder(basePath).getFiles(); 

                    var basePathFilesLen = basePathFiles.length; 

                     

                    for (var bsf = 0; bsf < basePathFilesLen; bsf ++){ 

                     

                                if (basePathFiles[bsf] instanceof Folder){ 

                                    var articleFolder = Folder(basePathFiles[bsf].fullName); 

                                    var articleFolderSubFolders = articleFolder.getFiles(); 

                                    var articleFolderSubFoldersLen = articleFolderSubFolders.length; 

                                         

                                    for (var i=0; i<articleFolderSubFoldersLen; i++){ 

                                            var currFolder = articleFolderSubFolders[i]; 

                                            var currFolderName = currFolder.name; 

                     

                                            var  articleFolder2 = Folder(currFolder + '\\' + currFolder.name + '_Inputs\\'); 

                                            var articleFolderSubFolders2 = articleFolder2.getFiles(); 

                                            var articleFolderSubFoldersLen2 = articleFolderSubFolders2.length; 

                     

                                            if (articleFolderSubFoldersLen2 > 4){ 

                     

                    ************************************** In below your code ***********************

                     

                                                var revision = articleFolderSubFolders2[articleFolderSubFoldersLen2-1].toString().split('_')[2]

                                                alert(currFolder.name +  "/" + revision)

                     

                                                    Report.writeln(articleFolder.name + "\t" + currFolder.name+ "\t" + revision + "\n") 

                     

                                                    } 

                                    } 

                                } 

                    Report.close();

                    **************************************

                     

                    Thanks In advance

                    • 7. Re: Write last folder naming
                      scriptworker Level 1

                      It has to do with the sortorder of the folders in the parent folder.

                      You should sort them first like this:

                       

                      var folders = ['90737_Final','90737_FirstProof','90737_R1','90737_R10','90737_R11','90737_R12','90737_R 13','90737_R14','90737_R2','90737_R3','90737_R4','90737_R5','90737_R6','90737_R7','90737_R 8','90737_R9'];

                       

                      var sorted = folders.sort(function(x,y)

                      {

                        var f1 = x.split('_')[1].match(/\d+/);

                        var f2 = y.split('_')[1].match(/\d+/);

                        return f1-f2;

                      });

                       

                      alert(sorted[sorted.length-1].split('_')[1]);

                      • 8. Re: Write last folder naming
                        karthiks94217840 Level 2

                        Hi SW,

                         

                        One more thanks,

                         

                        @Ok right: I understand that (thanks your good explain SW).

                         

                        @simple one question: How to get folder 14 "R14" alert?

                         

                        Thanks In advance

                        KS

                        • 9. Re: Write last folder naming
                          scriptworker Level 1

                          Well, if you do this:

                           

                          var sortedFolders = articleFolderSubFolders2.sort(function(x,y)

                          {

                            var f1 = x.split('_')[1].match(/\d+/);

                            var f2 = y.split('_')[1].match(/\d+/);

                            return f1-f2;

                          });

                           

                          alert(sortedFolders[sortedFolders.length-1].split('_')[1]);

                           

                          You should get the result you want.

                           

                          Michel