Click to See Complete Forum and Search --> : What is wrong with this code??


shanuragu
09-10-2003, 12:07 AM
Hi

I am trying to test whether a text file is empty or not. Here the code for the same.

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTickerFile = objFSO.GetFile(Server.MapPath(".") & "/scrollers/top_scroller.txt")

Set objTextStream = objTickerFile.OpenAsTextStream(ForReading)
strScrollerText = objTextStream.ReadAll

if (strScrollerText <> "")
Response.write("Not Empty")
else
Response.write("Empty")
End if

What is wrong with the above code??

shara

Superfly1611
09-10-2003, 03:04 AM
I pulled this off of something i wrote a while back - it was a VBSript so it may have a few issues with ASP - i'm not sure about that....


'***Name Source File an Path***
const FName = "c:\log.txt"

'***Declare File Read/Write modes***'
const forReading = 1, ForWriting = 2, ForAppending = 3
const triStateusedefault = -2, triStateTrue = -1, TriStateFalse=0

'***Create The File system Object***'
Dim FSO
set FSO = createobject("Scripting.FilesystemObject")

'***Pull the File into an Object***'
Dim File
set File = FSO.GetFile(FName)

'***Create Text Stream object***'
Dim textStream
set textStream = File.OpenAsTextStream(ForReading, triStateusedefault)

'***Conditional Loop to write to Output File***'
Dim strLine
strLine = ""
Do While not textStream.AtEndOfStream

'***Read Line into a variable***'
strLine = strLine & textStream.readLine

Loop

set TextStream = nothing
set FSO = nothing

If strLine <> "" Then....

Well you know what to do from there

Don't know if that'll help but good luck anyway