2 Replies Latest reply on Jan 7, 2011 10:03 AM by designmon79

    My files open and save two times

    designmon79

      Hi All,

       

      See my below script, when I run this script in my InDesign files within folders containing subfolders it open and save my folder files twice and subfolder files once.

       

      Could anybody please help me out why my folder files open and save twice. Subfolder code is working fine.

       

      Thanks,

      Mon

       

       

      See my below js code below.

       

       

      //my script starts

       

      var myFilePath = Folder.selectDialog("Please choose InDesign file folder");
      myFilePath = new Folder ([myFilePath]);
      myFilePathContents = myFilePath.getFiles("*.indd");
      mySubFolders(myFilePath);
      var myDocument = app.documents[0];
      for (var j = 0; myFilePathContents.length > j; j++) {
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
      var myDocument = app.open(myFilePathContents[j]);
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
      var myDoc = myDocument.layers.item(0);
      myDoc.printable=false
      app.activeDocument.close(SaveOptions.yes);
      }
      mySubFolders(myFilePath);
      function mySubFolders(theFolder) {
      var myFileList = theFolder.getFiles();
      for (var i = 0; i < myFileList.length; i++) {
      var myFile = myFileList[i];
      if (myFile instanceof Folder){
      mySubFolders(myFile);
      }
      else if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {
      myFilePathContents.push(myFile);
      }
      }
      }

      //my Script end

        • 1. Re: My files open and save two times
          milligramme Level 3

          folder
          ├── a.indd
          ├── b.indd
          └── subfolder
              ├── c.indd
              └── d.indd

           

           

          Hi, I run your code to folder like above,it open documents such as

           

          "a.indd, b.indd, a.indd, b.indd, c.indd, d.indd"

           

          a and b open twice.

           

          so fix code

           

          myFilePath = new Folder (myFilePath); // remove bracket for 'myFilePath'
          myFilePathContents = new Array(); // remove getting .indd, they are added later in mySubFolders()

           

           

          mySubFolders(myFilePath); // remove 2nd mySubFolders(), why run twice?

           

          and then, run code and documents will open like

           

          "a.indd, b.indd, c.indd, d.indd"

           

          mg

          • 2. Re: My files open and save two times
            designmon79 Level 1

            Thanks so much for your time. It is working now.

             

            Mon.