2 Replies Latest reply on Apr 24, 2017 9:12 AM by simonvg

    author mistake?

    simonvg

      Hi - has this author made a mistake here or is there something I'm just not getting? I can't understand how the 'saveDialog' method allows the user to specify an existing file. The text below in italics is copied from the book "InDesign CS5 Automation Using XML & JavaScript"

       

      ExtendScript does not offer a function for explicitly creating a file: instead, when the open() method is used with the mode argument set to "w", "e" or "a", if the file specified does not exist, it will be automatically created. Thus for example, the following statements will allow the user to either specify an existing file or create a new one.

      try{ var fleLog = File.saveDialog ("Log file location", "Text files: *.txt");

      fleLog.open("a");

      fleLog.write("\nStuff to be logged");

      fleLog.close(); }

      catch(err){ alert("Error. File could not be accessed.");

      }

       

      The file specified by the user is opened in append mode ("a") and then the appropriate text is written to the file. If the user specifies a file that does not exist, it will automatically be created.

       

      Any help would be much appreciated, have tried my best to understand this.

      Thanks!

        • 1. Re: author mistake?
          [Jongware] Most Valuable Participant

          I don't see an ontological problem here.

           

          For me, using the "saveDialog" in the example calls up a Save As dialog, with the title as given ("Log file location"), and I can type in a new file name in the blank field or select an existing one in the file selector. And of course I can also type in the name of an existing file.

           

          All software that allows an explicit "save as" is able to overwrite an existing file.

          • 2. Re: author mistake?
            simonvg Level 1

            Thanks for your quick reply. My "Save as" dialog doesn't allow me to choose an existing file without overwriting it. Unless I'm misunderstanding things, surely the idea here is to either choose an already existing file, without overwriting it, or create a new one?