2 Replies Latest reply on Mar 20, 2012 3:46 PM by apmaui808

    Stopping the File Open At the End of Loop


      How can I make the script skip the "docRef = open(fileList[i])" at the end of the iteration once all the files are opened? Is there a way to get rid of

      this by perhaps getting the total number of files on a folder and assigned it as a variable 'max", such that if the variable "i" is eventually equal to

      "max," the the script will not execute the last action on the iteration?


      As of now, this loop (taken from Paul Riggott's response to my question before regarding folder processing) is generating the following error:


      Error 8000: Cannot open the file because the open options are incorrect

      Line: 20

      -> docRef=open(fileList[i]);


      Here is the script I am working on:


      var startDisplayDialogs = app.displayDialogs

      app.displayDialogs = DialogModes.NO


      // ask the user for the input and output folders

      var inputFolder = Folder.selectDialog("Select a folder to process")

      var outputFolder = Folder.selectDialog("Select a folder for the output files")


      if (inputFolder != null && outputFolder != null) {


      // get all the files found in this folder

      var fileList = inputFolder.getFiles()


      // open each one in turn

      for (var i = 0; i < fileList.length; i++) {


      // The fileList includes both folders and files so open only files

      if (fileList[i] instanceof File && fileList[i].hidden == false) {


      // get a reference to the new document

      var docRef = open(fileList[i]);