11 Replies Latest reply on Sep 8, 2014 2:39 AM by Test Screen Name

    Exact pages path using regular wild card expression

    Jo_2013

      I have a script which will extract a pdf file to a predefined directory.

       

      The file path includes a text field in the parameter VendorNo.

       

      This is the actual windows directory path

      H:\ Drawing Office\PDF\Scripting Form Fields\Mail Merge\002 - Centrifuge

       

      The file path generated from the script  is

      H:\ Drawing Office\PDF\Scripting Form Fields\Mail Merge\002

       

      I need to include a wild card for the end part of the directory path for " - Centrifuge", as the end of the file path string may vary. 

       

      I have tried a regular expression wild card for any number of characters in the script such as    /./

       

      I have attempted this in the script as follows but it does not work.

       

      / Extract and save Form by calling folder level script
      var g = this.getField("VendorNo");
      var k = g.valueAsString;
      var l = k.match(/./);

      var j = this.numPages;

      var myPath = "/h/Drawing Office/PDF/Scripting Form Fields/Mail Merge/" + l + "/" + "test.pdf";

              this.extractPages(0,j-1,myPath);

      If anyone can please provide assistance with the regular expression, I would be most grateful.

        • 1. Re: Exact pages path using regular wild card expression
          Test Screen Name Most Valuable Participant

          I've never used regular expressions in JavaScript, but I have used them and I have this comment.

           

          . (period) alone means "any single character".

          .* means any number of characters

          ^.*$ means everyting, any number of characters from beginning to end of a line (i.e. the whole thing, or a whole line)

          • 2. Re: Exact pages path using regular wild card expression
            Test Screen Name Most Valuable Participant

            If though you're saying you don't know the directory name, just the start of it, that is never going to work, not with any method.

            • 3. Re: Exact pages path using regular wild card expression
              try67 MVP & Adobe Community Professional

              What you're trying to do is not possible.

              • 4. Re: Exact pages path using regular wild card expression
                Jo_2013 Level 1

                I have been trying a script from the console as a test with mixed results.

                 

                The aim is to search the directory for a folder containing the text from the PackageNo field and the result will be shown an an application alert as a test.

                 

                eg PackageNo field = 002 compare to the Directory path = /h/Drawing Office/PDF/Scripting Form Fields/Mail Merge/002 - Centrifuge

                 

                The first time the script was run it actually worked, but after the first time it came up with the console error

                sFolders is not defined

                8:Console:ExecException in line 8 of function top_level, script Console:Exec

                 

                I am at a loss on how to fix this error, if you can please test the script and advise where it is going wrong, I will be most grateful, thanks.

                 

                This is the script

                 

                var pack = this.getField("PackageNo").valueAsString;

                var topFolder = "/h/Drawing Office/PDF/Scripting Form Fields/Mail Merge/";
                   
                scanSubFolders(topFolder);
                // extract the package number from the directory name

                var f = sFolders.slice(0,3);

                // if the directory package number is equal to the RFT package no

                if (pack = f)   

                app.alert(f);

                 

                function scanSubFolders(tFolder) { // folder object, RegExp or string
                    var sFolders = new Array();
                  
                    sFolders[0] = tFolder;
                    for (var j = 0; j < sFolders.length; j++){ // loop through folders            
                      
                         }
                    
                };

                • 5. Re: Exact pages path using regular wild card expression
                  try67 MVP & Adobe Community Professional

                  The scanSubFolders method doesn't seem to do anything... It just contains an empty loop and doesn't return any value.

                  If all you want to do is check if a specific string is present in another string just use the indexOf method, or the test method.

                  • 6. Re: Exact pages path using regular wild card expression
                    Jo_2013 Level 1

                    Thank you for your reply.

                     

                    I have fixed so there is no empty loop and now have the entire script run from the function, and then  tested in the console.

                     

                    The console does not report back any errors but the application alert does not appear.

                     

                    The directory sub folder "002 - centrifuge" actually exists, so that the alert should show.

                     

                    Can you please give some insight as to why the script is not working?

                     

                     

                    var scanSubFolders = function(tFolder) { 

                    tFolder = "/h/QCC Drawing Office/PDF/Scripting Form Fields/Mail Merge/";

                        var sFolders = new Array();

                      

                        sFolders[0] = tFolder;

                        for (var j = 0; j < sFolders.length; j++){ // loop through folders            

                    var fileString = String(sFolders[j]);

                     

                    if (fileString = "002 - centrifuge")

                    {

                     

                     

                     

                    app.alert(fileString);

                        

                             }

                     

                    else 

                               scanSubFolders(sFolders[j]);  

                     

                    }  

                    };

                    • 7. Re: Exact pages path using regular wild card expression
                      Bernd Alheit Adobe Community Professional & MVP

                      sFolders[0] contains always "/h/QCC Drawing Office/PDF/Scripting Form Fields/Mail Merge/"

                        

                      Why do you overwrite the parameter tFolder at the beginning of the function?

                      • 8. Re: Exact pages path using regular wild card expression
                        try67 MVP & Adobe Community Professional

                        Also, this is a classic error:

                        if (fileString = "002 - centrifuge")


                        It needs to be:

                        if (fileString == "002 - centrifuge")

                        • 9. Re: Exact pages path using regular wild card expression
                          Jo_2013 Level 1

                          Thanks , appreciate all your help.

                           

                          I have modified the script as follows:

                          1. replaced the = sign to ==
                          2. Removed the reference to   sFolders[0] = tFolder;

                           

                          There are no errors in the console but the application alert is still not appearing.

                           

                          Can you advise why it would not be working?

                           

                          Script as follows:

                           

                          var scanSubFolders = function(tFolder) { 
                          tFolder = "/h/QCC Drawing Office/PDF/Scripting Form Fields/Mail Merge/";
                              var sFolders = new Array();
                               
                              for (var j = 0; j < sFolders.length; j++){ // loop through folders            
                          var fileString = String(sFolders[j]);

                          if (fileString == "002 - centrifuge")
                          {

                          app.alert(fileString);
                               
                                   }

                          else 
                                     scanSubFolders(sFolders[j]);  

                          }  
                          };

                          • 10. Re: Exact pages path using regular wild card expression
                            Bernd Alheit Adobe Community Professional & MVP

                            In nthis case sFolders is always empty. Why do you change the value of the function parameter tFolder ?

                            • 11. Re: Exact pages path using regular wild card expression
                              Test Screen Name Most Valuable Participant

                              I have no idea how you are trying to do what we have already says is impossible. There just doesn't seem to be anything in the script which even tries to scan a folder.