G'day All,
I'm using code below to check a path selected by a user.
Can anyone pick holes in it please?
The more critical you are the better.
tia
build
'GET SOURCE PATH --------------------------------------
inPath = Me.txtPath.Text
'CHECK PATH ----------------------------
If inPath = "" Then
'ToDo: Fix properly!
strTMP = "Select a bloody path, you idiot!"
sknMsg strTMP, 0
Exit Sub
Else
If flgFolder = True Then
If folderExists(in Path) Then
strTMP = "*.txt"
If Dir(inPath & "\" & strTMP) = "" Then
strTMP = "No text files in: " & inPath
sknMsg strTMP, 0
Exit Sub
End If
Else
strTMP = "Can't find: " & inPath
End If
Else
If Dir(inPath) = "" Then
strTMP = "Can't find: " & inPath
sknMsg strTMP, 0
Exit Sub
End If
End If
End If
Public Function folderExists(in Path As String) As Boolean
'folder doesn't exist
If Dir(inPath, vbDirectory) = vbNullString Then
folderExists = False
Else
folderExists = True
End If
End Function
Public Function fileExist(inPat h As String) As Boolean
If UCase(Dir(inPat h)) = UCase(TrimPath( inPath)) Then
fileExist = True
Else
fileExist = False
End If
End Function
Public Function TrimPath(ByVal inPath As String) As String
If Len(inPath) = 0 Then Exit Function
Dim i As Integer
Do
i = InStr(inPath, "\")
If i = 0 Then Exit Do
inPath = Right(inPath, Len(inPath) - i)
Loop
TrimPath = inPath
End Function
I'm using code below to check a path selected by a user.
Can anyone pick holes in it please?
The more critical you are the better.
tia
build
'GET SOURCE PATH --------------------------------------
inPath = Me.txtPath.Text
'CHECK PATH ----------------------------
If inPath = "" Then
'ToDo: Fix properly!
strTMP = "Select a bloody path, you idiot!"
sknMsg strTMP, 0
Exit Sub
Else
If flgFolder = True Then
If folderExists(in Path) Then
strTMP = "*.txt"
If Dir(inPath & "\" & strTMP) = "" Then
strTMP = "No text files in: " & inPath
sknMsg strTMP, 0
Exit Sub
End If
Else
strTMP = "Can't find: " & inPath
End If
Else
If Dir(inPath) = "" Then
strTMP = "Can't find: " & inPath
sknMsg strTMP, 0
Exit Sub
End If
End If
End If
Public Function folderExists(in Path As String) As Boolean
'folder doesn't exist
If Dir(inPath, vbDirectory) = vbNullString Then
folderExists = False
Else
folderExists = True
End If
End Function
Public Function fileExist(inPat h As String) As Boolean
If UCase(Dir(inPat h)) = UCase(TrimPath( inPath)) Then
fileExist = True
Else
fileExist = False
End If
End Function
Public Function TrimPath(ByVal inPath As String) As String
If Len(inPath) = 0 Then Exit Function
Dim i As Integer
Do
i = InStr(inPath, "\")
If i = 0 Then Exit Do
inPath = Right(inPath, Len(inPath) - i)
Loop
TrimPath = inPath
End Function
Comment