In a VBScript, I want to know if a file exists:
Set fso = CreateObject("Scripting.FileSystemObject")
If Not (fso.FileExists(file)) Then
msg = " doesn't exist."
End If
My files are on internal network.
Is there a way to distinguish:
- file really doesn't exist
- access denied
I try with fso.OpenTextFile
but the result for these two cases is always: Err.Number
= 5.
To distinguish between non-existing and non-accessible files you need .FileExists and .OpenTextFile:
Output:
Thanks to Ansgar's observation, the function can be improved: