PDA

View Full Version : Txt Files


Fuego
04-28-2004, 04:43 PM
I want a txt file that is going to be updated when it does exist
and created when it doesnt exist. Right now Im using this :

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(Server.MapPath("input/" & strJaar & strMaand & DatePart("d", Date()) & ".txt"), 8)
objTextFile.WriteLine StrekenLijst
objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing

But when there's no file it will error of course I tried as well the next

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(Server.MapPath("input/" & strJaar & strMaand & DatePart("d", Date()) & ".txt"), 8)
objTextFile.WriteLine StrekenLijst
objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing

But that one will error when I want to update it.
I thought using the ,8 would work for this...But it doesnt..
Anyone to help me out?

Roelf
04-28-2004, 08:40 PM
You had it almost, after the 2 arguments for the openTextFile method, you have to pass a third: True, it means create the file if it doesnt exist.

See for more info (http://www.devguru.com/Technologies/vbscript/quickref/filesystemobject_opentextfile.html)

Fuego
04-29-2004, 10:12 AM
Thnx a lot! Works fine now!