Results 1 to 8 of 8

Thread: PathMatchSpec Alternative

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    PathMatchSpec Alternative

    How can I use PathMatchSpec? Thanks
    Last edited by abazabam; May 13th, 2008 at 04:36 PM.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: PathMatchSpec Alternative

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: PathMatchSpec Alternative

    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: PathMatchSpec Alternative

    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.

  5. #5
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: PathMatchSpec Alternative

    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 ?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: PathMatchSpec Alternative

    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.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: PathMatchSpec Alternative

    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.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: PathMatchSpec Alternative

    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
    Last edited by abazabam; May 13th, 2008 at 04:35 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width