2 Replies Latest reply on Dec 10, 2009 9:05 AM by penyfai

    List files in dir with common name [JS]???

    penyfai Level 1

      I'm probably getting on everybodies' nerves now - and I know I should be trying harder to persuade my boss to get me 'Scripting InDesign CS3/4 with JavaScript' - by my saviour on many ocassions Peter Kahrel. I know, I know.

       

      I've only just cracked Applescript (crudely), now I've got to go cross-platform, and I'm a JS noob.

       

      All that said..... I'm having trouble trying to query files that all start with the same 8 digit number in a specific folder.

       

      In Applescript I was able to use:

      set servergraphics to (name of every file in folder graphicpath where name starts with adCID) as list

       

      This created a list of graphic files that I can match against.

       

      I've now tried every which way I can think of to replicate this line in JS - to no avail.

       

      Do I need to declare an array that contains the calculation?

       

      Thanks in advance - again

        • 1. Re: List files in dir with common name [JS]???
          Loic.Aigon Adobe Community Professional

          Hi,

           

          var theFolder = Folder("/your drive/your folder/");

          var theFiles = theFolder.getFiles();

          var theResult = [];

           

          for(i=0; i<theFiles.length; i++)

          {

               //Assuming is 8 numbers sequence is a static number.

               //You can also use grep to match 8 digits >

               // if(theFiles[i].name.match(/^\d{8}/);

           

              if(theFiles[i].name.indexOf("01234567")==0)     {

                    theResult.push(theFiles[i]);

               }

          }

           

          theResult;

          • 2. Re: List files in dir with common name [JS]???
            penyfai Level 1

            Great. That works a treat.

             

            I find it funny that Applescript normally takes more lines of code to do the job, but in certain instances is can replace multiple line with one.

             

            Ah, we all have our idiosyncrasies!

             

            Many thanks

            Andrew