title: Problem with counter in script Photoshop CS6 ver 13 64 bit
body: <p>I have script that<br />
  PSD (activeDocument) in "<em>3.Working</em> folder<br />  saves jpg<br /> in draft folders in directory "<em>../UserNameJobName/4.WIP/</em>" <br /><br />
  The problem is that everything works fine until I want to to create third draft folder (draft003).<br /> Then it saved again activeDocument in the same jpg file in draft002, instead of creating new folder draft003 and saving there respectivly. <br /><br />It seams that <code>var draftCounter</code> can't be higher than 2 value. I'm not sure where is a bug. What I know in photoshop CC it works without any problems.<br /><br />
  [Link to folder structure zip]
  <br /><a href="https://www.dropbox.com/s/kbalzsubs2477jy/191130_WARGAMES_LUKKAR.zip?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/kbalzsubs2477jy/191130_WARGAMES_LUKKAR.zip?dl=0</a></p>
  
  <p><a href="https://i.stack.imgur.com/a1rwM.png" rel="nofollow noreferrer">Main file directory pic</a><br />
  <a href="https://i.stack.imgur.com/iO4OP.png" rel="nofollow noreferrer">Draft directory pic</a></p>
  
  <p><br />code</p>
  
  <pre><code>#target photoshop;
  
  var wipCounter = 1;
  var fileNotFound = true;
  main();
  
  function main(){
      //Get file information
      var doc = app.activeDocument;
      var docName = doc.name;
      var docPath = doc.path;
  
      //Get the percentage to scale by
      var scaleValue = prompt("Enter the WIP JPEG scale percentage", "100");
  
      //Figure out the location of the WIP folder
      var savePath = docPath.toString();
      savePath = savePath.slice(0,-10);
      savePath = savePath + "/4.WIP/";
      var currDoc = docName.toString();
      currDoc = currDoc.slice(0,-4);
  
      //global variables are defined here
  
      //Look at the WIP folder and run a search for anything containing the word "draft"
      //Define the location of the WIP folder 
      var inWIPFolder = new Folder(savePath);
      //Look in each folder and create an array containing all of the information
      var fileList = inWIPFolder.getFiles();
      // Look at each array and sort the info out 
      for(var a=0; a&lt;fileList.length; a++) {
              //Exclude anything that is not a folder
              if(fileList[a] instanceof Folder) {
                  //convert each foldername to string for editing
                  var fileName = fileList[a].toString();
                  var draftSearch = fileName.search("draft");
                  if(draftSearch &gt; -1) {
                      var draftCounter  = fileName.slice(draftSearch);
                      if(fileNotFound == true) {
                          searchDraftFolder(draftCounter, savePath, currDoc);
                          }
                  }
              }
          }
  
  
          //Formatting the numbers
          if(wipCounter &lt; 10){
              wipCounter = "00" + wipCounter.toString();
           }else if(wipCounter &gt;= 10 &amp;&amp; wipCounter &lt; 100) {
               wipCounter = "0" + wipCounter.toString();  
           }
  
          //Define the path of the draft folders
          savePath = Folder(savePath +"/draft" + wipCounter);
          //Check to see if the draft folders exists. If not, make one
          if(!savePath.exists){
              savePath.create();
              }
  
          //Define the WIP file name with the incremental counter
          var wipFileName =savePath + "/" + currDoc + "_WIP" + wipCounter + ".jpg";
  
          //Resize the file
          doc.selection.selectAll();
          var blankLayer = doc.artLayers.add();
          blankLayer.name = "blankLayer";
          doc.selection.copy(true);
          doc.layers.getByName("blankLayer").remove();
  
          //Make new doc to paste into
          app.preferences.rulerUnits = Units.PIXELS;
          //arguments are: Width, Height, resolution, filename, colourspce, documentfill
          app.documents.add(UnitValue(doc.width, "PX"), UnitValue(doc.height, "PX"), doc.resolution, wipFileName, NewDocumentMode.RGB, DocumentFill.TRANSPARENT,1);
          app.activeDocument.paste();
          app.activeDocument.resizeImage(UnitValue(scaleValue, "PERCENT"), null, null, ResampleMethod.BICUBICSHARPER);
          //Save a RGBJpeg
          jpegFileSaver(app.activeDocument, new File(wipFileName), 10);
          //Close the new document down
          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
          //Deselect
          doc.selection.deselect();
          alert(currDoc + "WIP" + wipCounter + " saved.");
  }
  
  
  function searchDraftFolder(draftCounter, savePath, currDoc){
     var fileSearch = -1;
     //Define the location of each draft folder  
     var internalFolder = new Folder(savePath + "/" + draftCounter);
     //Look in each folder and create an array containing all of the information
     var internalFileList = internalFolder.getFiles();
     // Look at each array and sort the info out 
     for(var a=0; a&lt;internalFileList.length; a++) {
          //Exclude anything that is not a file
         if(internalFileList[a] instanceof File) {
             // convert each filename to string for editing
              var fileName = internalFileList[a].toString();
              //Searching the current document name and replacing spaces with %20
              var currDocStripped = currDoc.replace(/ /g, '%20');
              //Checking files until a result greater than 0 appears
              if(fileSearch === -1){
                  //search for the current file name
                  fileSearch = fileName.search(currDocStripped);
              }
             }
         }
     //if the filesearch does not return a result:
      if(fileSearch === -1){
          fileNotFound = true;
       //if it does return a result:
      } else {
          //Slice the number off the draft folder
          draftCounter = draftCounter.slice(-3);
          //convert the string into an integer
          draftCounter = parseInt(Number(draftCounter));
          //increment the number up
          wipCounter++;
          //terminate the main loop
          fileNotFound = false;
          }   
      }
  
  
  //A resuable JPEG save script
  function jpegFileSaver(doc, saveFile, quality){
      //define the save options
      var saveOptions = new JPEGSaveOptions();
      saveOptions.embedColorProfile = true;
      saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
      saveOptions.quality = quality;
      //save the files
      doc.saveAs(saveFile, saveOptions, true);
      }
  
  </code></pre>
  
  <p>Thanks in advance. <br />
  Additional credits to code author <a href="http://jamesmcdonald3d.com/" rel="nofollow noreferrer">http://jamesmcdonald3d.com/</a></p>