problem with 'Scripting.FileSystemObject'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bogey
    New Member
    • Jan 2007
    • 8

    #1

    problem with 'Scripting.FileSystemObject'

    Hi ,
    I tried to write a Line at the end of my file Test.txt.

    [HTML]function AddNewL(){
    var Object = new ActiveXObject(' Scripting.FileS ystemObject'); var LirTxt2 = Object.GetFile( "F:\Test.tx t");
    var ForWriting=2; //to be able to write
    var doc2 = LirTxt.OpenAsTe xtStream(ForWri ting,true); doc2.WriteLine( "byebye); //
    doc2.Close(); //close the file
    } [/HTML]


    But I can only manage to overwrite and i loose my first lines.
    If someone has a good idea,
    many thanks
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    You need to read the txt file first set the previous text to a variable then write it all back as one other than that I don't use FSO in my javascripts security problems with it.

    Comment

    • Bogey
      New Member
      • Jan 2007
      • 8

      #3
      Originally posted by iam_clint
      You need to read the txt file first set the previous text to a variable then write it all back as one other than that I don't use FSO in my javascripts security problems with it.
      Thank iam_clint for your advice

      Comment

      • Bogey
        New Member
        • Jan 2007
        • 8

        #4
        I am not sure to understand correctly,
        [HTML]
        function AddNewL(){
        var Object = new ActiveXObject(' Scripting.FileS ystemObject'); var LirTxt2 = Object.GetFile( "F:\Test.tx t");
        var ForReading = 1;
        var myText = LirTxt2.OpenTex tFile("F:\Test. txt", ForReading);
        myText = ts.ReadLine();
        var ForWriting=2; //to be able to write
        var doc2 = fso.OpenAsTextS tream(myText,tr ue); doc2.WriteLine( "byebye); //
        doc2.Close(); //close the file
        }[/HTML]

        It did not work.
        Please can you explain it again.thank

        Comment

        • iam_clint
          Recognized Expert Top Contributor
          • Jul 2006
          • 1207

          #5
          Code:
          doc2.WriteLine("byebye); //
           
          Needs to be
           
          doc2.WriteLine("byebye"); //
          Code:
          function AddNewL(){
          	var Object = new ActiveXObject('Scripting.FileSystemObject'); 	var LirTxt2 = Object.GetFile("F:\Test.txt"); 
          				var ForReading = 1;
          				 var myText = LirTxt2.OpenTextFile("F:\Test.txt", ForReading);
          				 myText = ts.ReadLine();
          	var ForWriting=2; //to be able to write
          var doc2 = fso.OpenAsTextStream(myText,true); 	
          doc2.WriteLine(myText+"byebye"); // 
          	doc2.Close(); //close the file
          }

          Comment

          • Bogey
            New Member
            • Jan 2007
            • 8

            #6
            Congratulation i_am clint ,
            Your solution is great .
            You saved my day.thanks

            Comment

            • sageman
              New Member
              • Jan 2007
              • 2

              #7
              I think you were using the wrong Const;
              ForReading = 1
              ForWriting = 2
              ForAppending = 8

              you wanted an 8 and you were using a 2. try an 8 and your original shorter code should work fine.

              Comment

              • Bogey
                New Member
                • Jan 2007
                • 8

                #8
                You are rigth Sageman, Thanks
                with 8 it's working

                Comment

                Working...