Search for folders

Source: Internet
Author: User
Option explicit

Private type browseinfo
Lnghwnd as long
Pidlroot as long
Pszdisplayname as long
Lpsztitle as long
Ulflags as long
Lpfncallback as long
Lparam as long
Iimage as long
End type

Private const bif_returnonlyfsdirs = 1
'Private const bif_returnonlyfsdirs = 100 -----> one more button for creating a folder
Private const max_path= 260

Private declare sub cotaskmemfree lib "ole32.dll "_
(Byval hmem as long)

Private declare function lstrcat lib "Kernel32 "_
Alias "lstrcata" (byval lpstring1 as string ,_
Byval lpstring2 as string) as long

Private declare function shbrowseforfolder lib "shell32 "_
(Lpbi as browseinfo) as long

Private declare function shgetpathfromidlist lib "shell32 "_
(Byval pidlist as long, byval lpbuffer as string) as long

Public Function browseforfolder (byval lnghwnd as long, byval strprompt as string) as string

On Error goto ehbrowseforfolder 'trap for errors

Dim intnull as integer
Dim lngidlist as long, lngresult as long
Dim strpath as string
Dim udtrauma as browseinfo

'Set API properties (housed in a UDT)
With udtrauma
. Lnghwnd = lnghwnd
. Lpsztitle = lstrcat (strprompt ,"")
. Ulflags = bif_returnonlyfsdirs
End

'Display the Browse folder...
Lngidlist = shbrowseforfolder (udtraumatic brain injury)

If lngidlist <> 0 then
'Create string of nulls so it will fill in with the path
Strpath = string (max_path, 0)

'Retrieves the path selected, places in the null
'Character filled string
Lngresult = shgetpathfromidlist (lngidlist, strpath)

'Frees memory
Call cotaskmemfree (lngidlist)

'Find the first instance of a null character,
So we can get just the path
Intnull = instr (strpath, vbnullchar)
'Greater than 0 means the path exists...
If intnull> 0 then
'Set the value
Strpath = left (strpath, intnull-1)
End if
End if

'Return the path name
Browseforfolder = strpath
Exit function 'abort

Ehbrowseforfolder:

'Return no value
Browseforfolder = empty

End Function


Private sub commandementclick ()
Debug. Print browseforfolder (Me. hwnd, "")
End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.