How can I use PathMatchSpec? Thanks
Printable View
How can I use PathMatchSpec? Thanks
I think you may have a problem with the API definition or the use of a Boolean to return the value from the API. This works ok for me
Code:Private Declare Function PathMatchSpec Lib "shlwapi.dll" Alias "PathMatchSpecA" _
(ByVal pszfile As String, _
ByVal pszspec As String) As Long
Private Sub Command1_Click()
Dim strFile As String
Dim strSpec As String
Dim lngReturn As Long
strFile = "c:\testdir\test.txt"
strSpec = "*.txt"
lngReturn = PathMatchSpec(strFile, strSpec)
If lngReturn <> 0 Then
Debug.Print strSpec & " exists in " & strFile
Else
Debug.Print strSpec & " does not exist in " & strFile
End If
strSpec = "*.doc"
lngReturn = PathMatchSpec(strFile, strSpec)
If lngReturn <> 0 Then
Debug.Print strSpec & " exists in " & strFile
Else
Debug.Print strSpec & " does not exist in " & strFile
End If
End Sub
Well, it does work but I have a file with a very long path that it doesn't work on. If you want to know how I was able to get the file path so long, the folder was originally on the desktop and then I moved it into 3 folders in My Documents. If I right-click on the file, it doesn't even have the properties option. I'm just trying to make sure it can handle everything so please don't tell me to move the folder to a shorter path or anything like that. Thanks
Sorry, I think I just need to do a little more research on this. Can you please delete this topic? I think I'm just getting mixed up here. Thanks for your code Doogle.
You have to be aware that the path cannot exceed MAX_PATH (260) characters in order to use that API.
Is there any particular reason why you can't use InStr or InstRev ?
Actually, I just got mixed up with some other part of my code. Thanks for the info. I would've use InStr but I wasn't sure exactly how PathMatchSpec worked so I thought maybe it was a lot more different from InStr.
Thanks for the PM abazabam, but we prefer not to delete threads once started (unless they violate our AUP or are duplicates).
Even though the OP may have found their own solutions, others may experience the same or similiar situation in which case, the resolution could benefit them.
In fact, I ask that you edit your first post, and reenter the originial question.
Thanks. :)
I don't think anyone else can have the same problem because I got mixed up and what I said in my original post wasn't true. Maybe I'll just change it to something that works. Can you please change the title to "PathMatchSpec" and delete my other posts in this page? Thanks