FileExists functions - Not capturing Error 52 correctly

themanof83

Registered User.
Local time
Today, 08:40
Joined
May 1, 2008
Messages
73
Morning All,

I have been having issues with a number of functions trying to capture a 'Bad File Name' or 'File Does Not Exist' error (#52), before it occurs. I was wondering whether I am doing something fundamentally wrong as nobody else has seemingly struggled with this.

There are a large number of FileExists() functions out there provided in tutorials all, pretty much, doing the same thing - returning FileExists as a Boolean. I've tried a few all with the same outcome, take the following provided by Allen Browne as my implemented example:

http://www.everythingaccess.com/tutorials.asp?ID=FileExists()-and-FolderExists()

My problem is that I'm getting Error 52 when the filepath string gets passed to the Dir() function when evaluating FileExists. Therefore FileExists never gets the chance to be returned False as it is interupted by Error 52!!? This occurs even when I add an error handler to trap Error 52. My string is as per the recommended format:

FileExists("\\MyServer\Wotsit")

Your help would be muchly appreciated.

Cheers :)
 
Ok, found two seperate FSO approaches that seemingly work for files and folders...

Code:
Function FileExists(filespec As String) As Boolean
   FileExists = CreateObject("Scripting.FileSystemObject").FileExists(filespec)
End Function
 
Function FolderExists(filespec As String) As Boolean
   FolderExists = CreateObject("Scripting.FileSystemObject").FolderExists(filespec)
End Function
 

Users who are viewing this thread

Back
Top Bottom