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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using objFileSys to check a file exists

Status
Not open for further replies.

jakeyg

Programmer
Mar 2, 2005
517
GB
I'm using an if-then-else statement, to check if a file exists before reading it in.

if (objFileSys.FileExists("C:\hello.txt")) then
Set objTextStream = objFileSys.OpenTextFile
("C:\hello.txt",1)
else
"File doesn't exist message"
end if

Whether the file exists or not it always goes to the else statement.

If I try (objFileSys.FileExists("C:\hello.txt")= False) then the file is read in if it's there and crashes if it isn't.

Copied the code from the web and verifyed it and my syntax looks right, but for some reason it doesn't seem to be checking it properly

I'm I missing something (again) or are there other factors which can influence objFileSys???

thanks
 

You've declared the filesystem object? Also, once you have declared it the outside parenthesis should not be necessary. Should look something like this:
Code:
Dim objFileSys, objTextStream

Set objFileSys = CreateObject("Scripting.FileSystemObject")

If objFileSys.FileExists("C:\hello.txt") Then
    Set objTextStream = objFileSys.OpenTextFile("C:\hello.txt",1)
Else
    Response.Write "File doesn't exist."
End If

One more thing, does the file exist?
 
Yeah, got that in
It's all the more bizarre cause I've taken the code from another ASP file where the code works fine as it is. [ponder]
 

... and the file actually exists, right? Stupid question hopefully, but most answers here are for simple oversights.

 
yeah, it's there ;-) put an HREF to it to make sure [3eyes]

The other one looks at an IP address for the file i.e. "I've changed this new one to look at the path
i.e. "c:\inetpub\hello.txt" and it works now

curioser and curioser
ah well, it's working now, I'll just forget about it for now and worry about it if it breaks again

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top