Easily check whether any file or folder exists or not using 1. 'FileSystemObject' 2. 'Dir' (VB Buil
Easily check whether any file or folder exists or not using 1. 'FileSystemObject' 2. 'Dir' (VB Built-In)
Rate Easily check whether any file or folder exists or not using 1. 'FileSystemObject' 2. 'Dir' (VB Buil
(1(1 Vote))
'Error handling
On Error GoTo errFPE
'File System Object
Dim fso As Object
'Create object now
Set fso = CreateObject("Scripting.FileSystemObject")
'Check if exists or not
FolderPathExist = fso.FolderExists(sDir)
Exit Function
errFPE:
MsgBox Err.Description, vbCritical, "Error " & Err
Err.Clear
FolderPathExist = False
End Function
Public Function FilePathExists(sFile As String) As Boolean
'Error handling
On Error GoTo errFPE
'File System Object
Dim fso As Object
'Create object now
Set fso = CreateObject("Scripting.FileSystemObject")
'Check if exists or not
FilePathExist = fso.FileExists(sDir)
Exit Function
errFPE:
MsgBox Err.Description, vbCritical, "Error " & Err
Err.Clear
FilePathExist = False
End Function
'----COMBINE ALTERNATE----
Public Function PathExist(sPath As String, Optional bFolder As Boolean = False) As Boolean
'Error Handling
On Error GoTo errPE
Dim iAttrib As Integer
PathExist = False
sPath = Trim$(sPath)
If sPath = "" Then Exit Function
iAttrib = IIf(bFolder, vbDirectory, vbNormal)
If Len(Dir$(sPath, iAttrib)) > 0 Then PathExist = True
Exit Function
errPE:
MsgBox Err.Description, vbCritical, "Error " & Err
Err.Clear
PathExist = False
End Function
'Please tell me if there is any bug, b'coz then only one can learn more
Easily check whether any file or folder exists or not using 1. 'FileSystemObject' 2. 'Dir' (VB Buil Comments
No comments yet — be the first to post one!
Post a Comment