Home All Groups Group Topic Archive Search About
Author
5 Mar 2006 9:57 AM
Ron
Hi
Mike Sutton gave me a link to this code, but I would like to extend its
search power but I am not sure how to do this can you help please.

Option Explicit
Private Declare Function SHGetSpecialFolderPath Lib "Shell32.dll" Alias _
    "SHGetSpecialFolderPathA" (ByVal hWndOwner As Long, ByVal lpszPath As
String, _
    ByVal nFolder As Long, ByVal fCreate As Long) As Long

Private Const CSIDL_MYMUSIC As Long = &HD
Private Const MAX_PATH As Long = 260
Private gName As String


Private Sub Form_Load()
gName = InputBox("Enter Name", "Get Name", , 5000, 3000)
    Debug.Print """" & GetMyMusicFolder() & "\" & gName ' """"
    Text1.Text = GetMyMusicFolder & "\" & gName
End Sub

Private Function GetMyMusicFolder() As String
    Dim StrBuf As String

    StrBuf = Space$(MAX_PATH)
    If (SHGetSpecialFolderPath(Me.hWnd, StrBuf, CSIDL_MYMUSIC, 0&)) Then _
        GetMyMusicFolder = TrimNull(StrBuf)
End Function

Private Function TrimNull(ByRef inString As String) As String
    Dim NullPos As Long

    NullPos = InStr(1, inString, vbNullChar)
    If (NullPos) Then TrimNull = Left$(inString, NullPos - 1) Else TrimNull
= inString
End Function
'***

'Here 's a quick function for you, drop a text box on a form then set it's
'MultiLine property to "True" and it's ScrollBars property to "3 - Both" then
'paste this code in and run:

I have changed it slightly and it does show the path I want, but I want the
user to know that there is a CD in his/her My Music  folder of  say "An
Artists Name" type "The Name" into a text box or inputbox and get the path to
that artists. Can this be done please

Author
5 Mar 2006 10:40 AM
Mike D Sutton
> Mike Sutton gave me a link to this code, but I would like to extend its
> search power but I am not sure how to do this can you help please.
<code snipped>
> I have changed it slightly and it does show the path I want, but I want the
> user to know that there is a CD in his/her My Music  folder of  say "An
> Artists Name" type "The Name" into a text box or inputbox and get the path to
> that artists. Can this be done please

Use the Dir() function on the path you're currently getting to list all the files/folders in there, and see if any match
your search criteria.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
5 Mar 2006 2:59 PM
Ron
Hi Mike
Sorry as I am still trying to learn Vb can you expand on what you said in
your last post to use Dir() function.
Thanks

Show quoteHide quote
"Mike D Sutton" wrote:

> > Mike Sutton gave me a link to this code, but I would like to extend its
> > search power but I am not sure how to do this can you help please.
> <code snipped>
> > I have changed it slightly and it does show the path I want, but I want the
> > user to know that there is a CD in his/her My Music  folder of  say "An
> > Artists Name" type "The Name" into a text box or inputbox and get the path to
> > that artists. Can this be done please
>
> Use the Dir() function on the path you're currently getting to list all the files/folders in there, and see if any match
> your search criteria.
> Hope this helps,
>
>     Mike
>
>
>  - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
>
Author
5 Mar 2006 4:11 PM
Mike D Sutton
> Sorry as I am still trying to learn Vb can you expand on what you said in
> your last post to use Dir() function.

Try this:

'***
Private Sub ScanMusicFolder()
    Dim MusicPath As String
    Dim DirRet As String

    MusicPath = AppendTrailingSlash(GetMyMusicFolder())

    DirRet = Dir$(MusicPath, vbAlias - 1)
    Do While Len(DirRet)
        If (GetAttr(MusicPath & DirRet) And vbDirectory) Then
            If (Len(Replace(DirRet, ".", ""))) Then _
                Debug.Print "FOLDER: " & DirRet
        Else
            Debug.Print "FILE: " & DirRet
        End If

        DirRet = Dir$()
    Loop
End Sub

Public Function AppendTrailingSlash(ByRef inPath As String, _
    Optional ByVal inPathDelimiter As String = "\") As String
    If (Right$(inPath, Len(inPathDelimiter)) = inPathDelimiter) Then _
        AppendTrailingSlash = inPath Else _
        AppendTrailingSlash = inPath & inPathDelimiter
End Function
'***

Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
5 Mar 2006 5:50 PM
Ron
Hi Mike
Thank you very much, I am now building the code and the results are as I
wanted. Thank you for you time and trouble

Show quoteHide quote
"Mike D Sutton" wrote:

> > Sorry as I am still trying to learn Vb can you expand on what you said in
> > your last post to use Dir() function.
>
> Try this:
>
> '***
> Private Sub ScanMusicFolder()
>     Dim MusicPath As String
>     Dim DirRet As String
>
>     MusicPath = AppendTrailingSlash(GetMyMusicFolder())
>
>     DirRet = Dir$(MusicPath, vbAlias - 1)
>     Do While Len(DirRet)
>         If (GetAttr(MusicPath & DirRet) And vbDirectory) Then
>             If (Len(Replace(DirRet, ".", ""))) Then _
>                 Debug.Print "FOLDER: " & DirRet
>         Else
>             Debug.Print "FILE: " & DirRet
>         End If
>
>         DirRet = Dir$()
>     Loop
> End Sub
>
> Public Function AppendTrailingSlash(ByRef inPath As String, _
>     Optional ByVal inPathDelimiter As String = "\") As String
>     If (Right$(inPath, Len(inPathDelimiter)) = inPathDelimiter) Then _
>         AppendTrailingSlash = inPath Else _
>         AppendTrailingSlash = inPath & inPathDelimiter
> End Function
> '***
>
> Hope this helps,
>
>     Mike
>
>
>  - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
>