Appending Text to a .txt file

Results 1 to 3 of 3

Thread: Appending Text to a .txt file

  1. #1
    D.H. Guest

    Default Appending Text to a .txt file

    I am trying to open up a .txt file and add some text to the file(based on some event) using the FileSystemObject, but I keep getting errors. <BR><BR>I : <BR>set obj=server.createobject("Scripting.filesystemobjec t") <BR>set objfile=obj.OpenTextFile("/schedule.txt") <BR>objfile.writeline("whatever") <BR><BR>but i get errors, and it also says that it doesn&#039;t understand the &#039;ForAppending&#039; that also returns an error. <BR><BR>Can someone shed some light on this for me????

  2. #2
    Join Date
    Dec 1969

    Default RE: Appending Text to a .txt file

    OK I&#039;m not sure what kind of an error you are getting but I did it this way and it worked for me try it and if you get an error tell ue what is is and where;<BR><BR>&#039;Append whatever the schedule textfile<BR> Dim FileName, objFSO<BR> const ForAppending = 8<BR> FileName = Server.MapPath("schedule.txt")<BR> set objFSO = CreateObject("Scripting.FileSystemObject")<BR><BR> Dim obj<BR><BR> If objFSO.FileExists(strLogFileName) Then<BR> Set obj = objFSO.OpenTextFile(FileName, ForAppending)<BR> Else<BR> Set obj = objFSO.CreateTextFile(FileName)<BR> End If<BR> <BR> obj.WriteLine ("whatever")<BR> obj.close<BR> Set obj = Nothing<BR> Set objFSO = Nothing<BR><BR>Try that,<BR>Donnacha

  3. #3
    Join Date
    Dec 1969

    Default RE: Appending Text to a .txt file

    Are you adding the aurgument to append?<BR><BR>First, if you use the number equivalents, you do not need some cases, you will get a flag for "aliens" if file is not accessable to your application<BR><BR>1 = ForReading<BR>2 = ForWriting<BR>8 = ForAppending<BR><BR>ie...<BR><BR>Dim file<BR><BR>file = "/schedual.txt"<BR><BR>set obj=server.createobject("Scripting.filesystemobjec t") <BR>set objfile=obj.OpenTextFile(file, 8, false)<BR>objfile.writeline("whatever") <BR><BR>The third arg is for "if the file does not exist, create it". Options are true and false...false natuarally is "do not create the file if it does not exist"<BR><BR>see if you get it to fire with this.<BR><BR>Tim<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts