using FileExists method of FSO

Results 1 to 2 of 2

Thread: using FileExists method of FSO

  1. #1
    vdn Guest

    Default using FileExists method of FSO

    hi i am having problems using fileExists() method for whatever reason it doesn&#039t do anything for me. Here is the code that give me a headache. It should append to a file only if it exists ,if it doesn&#039t it should create it and then write to it. The creation is going fine, but appending later on to it never happens. What&#039s happening ? Here is source. Thank you.<BR><BR>&#060;%<BR> Dim country,visit,FSO<BR> <BR> country = Request.querystring("country") <BR> visit = Request.querystring("session")<BR><BR> Set fso = Server.CreateObject("Scripting.FileSystemObject")< BR> <BR> if fso.FileExists(Server.mappath("/vdn/db/country.txt")) then<BR> Set TextStream = fso.OpenAsTextStream(8, True) <BR> TextStream.writeline(country & vbtab & now()) <BR> else<BR> Set TextStream = fso.CreateTextFile(Server.mappath("/vdn/db/country.txt"), True)<BR> TextStream.writeline(country & vbtab & now())<BR> TextStream.writeLine(Server.Mappath("vdndbcountry. txt"))<BR> TextStream.writeLine(Server.Mappath("/vdn/db/country.txt"))<BR> TextStream.writeLine("True")<BR> end if<BR>TextStream.close<BR>%&#062;

  2. #2
    lagerBoy Guest

    Default RE: using FileExists method of FSO

    It looks like you&#039re trying to append to the fso. You&#039ve assigned your TextStream variable incorrectly. Try this:<BR><BR>Dim country, visit<BR>Dim fso, TextStream<BR>Dim yourFile, blnExists, objFile<BR><BR>country = "Australia"<BR>visit = "1"<BR>yourFile = (Server.mappath("/country.txt"))<BR><BR>Set fso = Server.CreateObject("Scripting.FileSystemObject")< BR><BR>blnExists = fso.FileExists(yourFile)<BR>if blnExists then<BR>Set objFile = FSO.GetFile (yourFile)<BR>Set TextStream = objFile.OpenASTextStream(8, True) <BR>TextStream.writeline(country & vbtab & now()) <BR>else<BR>Set TextStream = fso.CreateTextFile(yourFile, True)<BR>TextStream.writeline(country & vbtab & now())<BR>TextStream.writeLine(yourFile)<BR>TextSt ream.writeLine(yourFile)<BR>TextStream.writeLine(" True")<BR><BR>end if<BR>TextStream.close

Posting Permissions

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