Checking to see if "file_doesnt.asp" exists:
False
Function Version:
Checking to see if "file_exists.asp" exists:
True
Checking to see if "file_doesnt.asp" exists:
False
I recently received an email from a visitor that wanted a quick and easy way to
find out if a file exists on the server's file system. Not having a lot of
information about the intended use, I wasn't sure if I should wrap it up in a function of not.
As you could probably tell from the output above I decided to offer both versions.
The first implementation if useful if you're checking that the file exists before
doing something else via the FileSystemObject (FSO). In that case you can use the
same FSO used to check for the file's existance to do whatever else you need to do.
If, on the other hand, you're just checking if the file exists before passing control
off to another function or checking that an XML file exists before loading it
into an XML parser then the nice neat little function will probabably be the better choice.
Anyway, I've included both so you can choose whichever version makes sense for your situation.