FileExists

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am a novice to VB scripting. I want to test the existance of a file. If
it exists I want to delete it. How do I pass the path and filename to the
FileExist command?
 
Simplest way is

If Len(Dir(FullPathToFile)) > 0 Then
Kill FullPathToFile
End If

Unfortunately, that can cause problems if you're using Dir for other
purposes. If you are, then here's a function you can use:

Function FileExists(FullPathToFile As String) As Boolean
On Error Resume Next

FileExists = (GetAttr(FullPathToFile) And vbDirectory) = 0

End Function
 
Back
Top