Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading text files

Status
Not open for further replies.

Sarky78

Programmer
Oct 19, 2000
878
GB
Right I have got the following code, that seems to be hanging our server for some unknown reason. the files that it is looking for exist and they are in the right directory. when I run this code it gets as far as the OpenTextFile line and then does absolutly nothing, does anyone know what could be wrong with this line, can you see anything that i am doing wrong somewhere else?

thanks in advance for any help !

filepath = "srchdir/" & rs("filename")
sFileName = Server.MapPath (filepath)
set fsoObj = Server.CreateObject "Scripting.FileSystemObject")
if fsoObj.fileExists(sFileName) then
set objTextFile = fsoObj.OpenTextFile(sFileName)
while not objTextFile.AtEndOfStream
lineval = objTextFile.ReadLine
if Left(lineval,5) = "#####" then
linelen = Len(lineval)
linkval = Right(lineval, (linelen-5))
end if
if Left(lineval,5) = "%%%%%" then
linelen = Len(lineval)
headval = Right(lineval, (linelen-5))
end if
wend

objTextFile.close
set objTextFile = nothing
set fsoObj = nothing
end if
 


arperry,

I suggest that you write each line to the page to make sure it is reading the line first.

lineval = objTextFile.ReadLine
response.write lineval & &quot;<br>&quot;

From there, you can test your logic.
fengshui1998
 
hi thanks for the quick response

I can't do that as I know that it is failing at the line:

set objTextFile = fsoObj.OpenTextFile(sFileName)

so this is before i have opened the file so therefore i can't read the file, this is the problem that i am getting. i put a response.write before and after the above line. the one before prints out, the one after doesn't leading me to believe that it is failing to open the file in the first place.

what could be causing this? problem with server component?
 

Try this to determine what's happeing on opening the file,

set fsoObj = Server.CreateObject &quot;Scripting.FileSystemObject&quot;)
if fsoObj.fileExists(sFileName) then
On error Resume Next
set objTextFile = fsoObj.OpenTextFile(sFileName)
If err.number <> 0 then
response.write err.number & &quot; &quot; & err.description
response.end
err.clear
End if
while not objTextFile.AtEndOfStream
 
If you copied straight from your script, then your missing an open paren in the third line:

set fsoObj = Server.CreateObject &quot;Scripting.FileSystemObject&quot;)

should be

set fsoObj = Server.CreateObject (&quot;Scripting.FileSystemObject&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top