1 Reply Latest reply on Dec 12, 2009 1:06 AM by Thom Parker

    Incrementally name file with saveAs

    kentgbaker

      Hello all,

       

      I am trying to create a script that names the active file as w1.pdf, and then subsequently would name the file w2, etc.

       

      If one were working on w9.pdf and ran the script, you guessed it..........w10.pdf

       

      Can I use the increment operand with saveAs? All of my efforts just keep adding stuff to the file name, not incrementtally changing the file name.

       

      Thanks in advance for any help,

        • 1. Re: Incrementally name file with saveAs
          Thom Parker Adobe Community Professional

          Hello Kent,  Yes of course this can be done.  But of course it has to be done from a folder level script, since the saveAs function cannot be used from a document script.

           

          The basic technique is to acquire the file name, determine whether or not it matches the expected format, and parse out the current number.  Then increment the number and generate a new file name.

           

          For example, this code uses a regular expression to perform the task:

           

          // Match "w" followed by one or two digits

          var rgFlNm = /^w(\d{1,2})/;

          if(rgFlNm.test(this.documentFileName))

          {

             var newFileName = "w" + (Number(RegExp.$1) + 1).toString();

             this.saveAs(newFileName);

          }

          else

             app.alert("File Name does not match expected format");

           

           

          the code here displays an alert if the file name format does not match "w" followed by one or two digits.  But you could have it default the file name or ask the user what they want to do.

           

          Thom Parker
          The source for PDF Scripting Info
          pdfscripting.com

           

          The Acrobat JavaScript Reference, Use it Early and Often
          http://www.adobe.com/devnet/acrobat/javascript.html

           

          Then most important JavaScript Development tool in Acrobat
          The Console Window (Video tutorial)
          The Console Window(article)