9 Replies Latest reply on Nov 1, 2010 4:37 AM by Haakenlid

    Want to replace content in existing text file

    tansk02 Level 1

      Hi All,

       

      Below is the script to write text. It is running good but it adds text after existing text.

       

      I want to save this text file in my selected folder and replace exsiting text as well as open that text file automatically in front of all my open application.

       

      Please help.

       

      Thanks in advance.

       

       

      function write(text){

      var myDoc=app.activeDocument;

      var myTextFilePath=myDoc.filePath + "/" + "mytextfile" + ".txt";

      var myTextFile = new File(myTextFilePath);

      if ( myTextFile.exists )

      {

      myTextFile.open("e");

      myTextFile.seek(0, 2);

      }

      else {

      myTextFile.open("w");

      }

      myTextFile.write(text+"\r");

      }