faqts : Computers : Programming : Languages : Asp : ASP/VBScript : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

60 of 73 people (82%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I check if a file exists (on the server in the current directory)?
How can I append an existing text file?
How can I create a text file using ASP?

Jul 17th, 2000 05:25
unknown unknown, Darren Hoefgen


Problem:
How does one check to see if a text file exists (on the server in the 
current directory) and if it exists then append to it, else, if it does 
not exist, create it and write a record to it.
Solution:
Set fs = CreateObject("Scripting.FileSystemObject")
if fs.fileexists(FILENAMEANDPATH) then
    Set f = fs.OpenTextFile("c:\testfile.txt", 
ForAppending,TristateFalse)
else
    Set f = fs.CreateTextFile("c:\testfile.txt", True)
end if
fs.writeline(BLAH)
fs.close
set fs = nothing
set f = nothing
something similar to that -- used code from MSDN -- check it out for
yourself http://msdn.microsoft.com/library/default.asp



© 1999-2004 Synop Pty Ltd