F
franky
I'm trying to create a function to see if a file exists in a directory.
Sometimes, I only have the begining part of a file name and need to use a
wildcard for the rest. How would I do this?
The following function works (got off web) if the file name is explicitly
there but returns "false" if I attempt to put a wildcard in any part of the
argument.
ie: "c:\test*.txt"
Function DoesFileExist(strFileSpec As String) As Boolean
' Return True if file specified in the
' strFilespec argument exists.
' Return False if strFileSpec is not a valid
' file or if strFileSpec is a directory.
Const INVALID_ARGUMENT As Long = 53
On Error GoTo DoesfileExist_Err
If (GetAttr(strFileSpec) And vbDirectory) <> vbDirectory Then
DoesFileExist = CBool(Len(Dir(strFileSpec)) > 0)
Else
DoesFileExist = False
End If
DoesfileExist_End:
Exit Function
DoesfileExist_Err:
DoesFileExist = False
Resume DoesfileExist_End
End Function
Thanks in advance!
Sometimes, I only have the begining part of a file name and need to use a
wildcard for the rest. How would I do this?
The following function works (got off web) if the file name is explicitly
there but returns "false" if I attempt to put a wildcard in any part of the
argument.
ie: "c:\test*.txt"
Function DoesFileExist(strFileSpec As String) As Boolean
' Return True if file specified in the
' strFilespec argument exists.
' Return False if strFileSpec is not a valid
' file or if strFileSpec is a directory.
Const INVALID_ARGUMENT As Long = 53
On Error GoTo DoesfileExist_Err
If (GetAttr(strFileSpec) And vbDirectory) <> vbDirectory Then
DoesFileExist = CBool(Len(Dir(strFileSpec)) > 0)
Else
DoesFileExist = False
End If
DoesfileExist_End:
Exit Function
DoesfileExist_Err:
DoesFileExist = False
Resume DoesfileExist_End
End Function
Thanks in advance!