From: Norm on
Hi,

I have a program called PTPruner from Karen Kenworthy, that has a problem I
am not sure how to get around. I have emailed her, but I assume she is
pretty busy and maybe she might still be hanging around here. :-)

Anyway the code with the problem is below, it is a search routine to see if
an entry in the registry still exists on the computer and it actually works
fairly well, except with the one part which looks for a space and then
strips out the left part to the space and checks if it exists, if it does
the program marks it as true. The problem and I have marked the code, is
that even with a false entry I placed in the registry it marks it as true,
because it is striping out to a final path to check as C:\Program, which I
would think would almost always come back as existing.

If I rem out this part some of the other programs that do exist come back as
not there, so I am not sure how to get around this and would appreciate any
help.

If you need more of the other routines let me know.

Thanks Norm,

Code is below----The problem is in the FileExist2 Function


Function FileExist(fn As String) As Boolean
Dim name As String
Dim fl As Long

On Error Resume Next

name = Trim$(fn)
FileExist = False

If Len(name) = 0 Then Exit Function

fl = 0
Err = 0

On Error Resume Next

fl = FileLen(name)

If Err = 0 Then
FileExist = True
End If

End Function




Function FileExist2(fn As String) As Boolean
Dim name As String
Dim fl As Long
Dim i As Long

On Error Resume Next

name = Trim$(fn)
FileExist2 = False

If Len(name) = 0 Then Exit Function
FileExist2 = True

If FileExist(name) Then Exit Function

If Left$(name, 1) = Chr$(34) Then ' quoted string
i = InStr(2, name, Chr$(34))

If i > 0 Then
name = Mid$(name, 2, i - 2)
End If

End If

i = InStr(1, name, ",")

If i > 0 Then
name = Trim$(Left$(name, i - 1))

If FileExist(name) Then Exit Function
End If

If InStr(1, LCase$(name), "rundll") > 0 Then
i = InStr(1, name, " ")

If i > 0 Then
name = Trim$(Mid$(name, i + 1))

If FileExist(name) Then Exit Function
End If

End If

If FileExist(name) Then Exit Function

i = InStr(1, name, "/")

If i > 0 Then
name = Trim$(Left$(name, i - 1))

If FileExist(name) Then Exit Function
End If

name = Replace(name, "\\", "\")

If FileExist(name) Then Exit Function

i = Len(name)

Do While i > 0

If Mid$(name, i, 1) = " " Then Exit Do
i = i - 1
Loop

This is the problem code!!!
If i > 0 Then
name = Trim$(Left$(name, i))
If FileExist(name) Then Exit Function
End If

i = InStr(1, name, " ")

If i > 0 Then
name = Trim$(Left$(name, i))

If FileExist(name) Then Exit Function
End If
The problem ends here!!!


If FileExist(WinDir & "\" & name) Then Exit Function

If FileExist(WinSysDir & "\" & name) Then Exit Function
FileExist2 = FileExist(name)

End Function