BetaONE will rise again!

BetaONE will rise again! (http:\\b1.hcanet.com\forum/index.php)
-   Coders Corner (http:\\b1.hcanet.com\forum/forumdisplay.php?f=57)
-   -   Code Bank: Browseforfolder, Getfolderlocation (http:\\b1.hcanet.com\forum/showthread.php?t=10255)

~*McoreD*~ 30th Dec 03 02:56 AM

Browse for Folder and get the Folder Location

Requirements:
CommandButton -- Name: cmdBrowse
TextBox -- Name: txtRemotePath

Code:

Private Declare Function SHBrowseForFolder Lib "shell32.dll" (ByRef lpbi As Browseinfo) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long

Private Type Browseinfo
    hwnd As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Integer
    End Type

Private Sub cmdBrowse_Click()

Dim fret As Long
Dim buffer As String, folder As String
Dim bInfo As Browseinfo
'---------------------
    bInfo.hwnd = Me.hwnd
    bInfo.pszDisplayName = Space(255)
    bInfo.ulFlags = &O1
    bInfo.iImage = 0
    bInfo.lParam = 0
    bInfo.lpfn = 0
    bInfo.pidlRoot = 0
    bInfo.lpszTitle = "Select the folder of your choice."
    buffer = Space(255)
    fret = SHGetPathFromIDList(SHBrowseForFolder(bInfo), buffer)
    buffer = RTrim(buffer)
    folder = Left(buffer, Len(buffer) - 1)
 &nbsp; &nbsp;If folder <> vbNullString Then 'user selected OK
 &nbsp; &nbsp;If Right(folder, 1) <> "\" Then folder = folder + "\"
 &nbsp; &nbsp;txtRemotePath.Text = folder
End If
End Sub

Enjoy!

Thankbot 30th Dec 03 02:56 AM

2 Users already said Thank You!

TheMysterio, robinwilson16,

~*McoreD*~ 30th Dec 03 02:59 AM

Browse for Folder and get the Folder Name.

Change the cmdBrowse_Click() event to this:

Code:

Private Sub cmdBrowse_Click()

Dim fret As Long
Dim buffer As String, folder As String
Dim bInfo As Browseinfo
'---------------------
 &nbsp; &nbsp;bInfo.hwnd = Me.hwnd
 &nbsp; &nbsp;bInfo.pszDisplayName = Space(255)
 &nbsp; &nbsp;bInfo.ulFlags = &O1
 &nbsp; &nbsp;bInfo.iImage = 0
 &nbsp; &nbsp;bInfo.lParam = 0
 &nbsp; &nbsp;bInfo.lpfn = 0
 &nbsp; &nbsp;bInfo.pidlRoot = 0
 &nbsp; &nbsp;bInfo.lpszTitle = "Select the folder of your choice."
 &nbsp; &nbsp;buffer = Space(255)
 &nbsp; &nbsp;fret = SHGetPathFromIDList(SHBrowseForFolder(bInfo), buffer)
 &nbsp; &nbsp;buffer = RTrim(buffer)
 &nbsp; &nbsp;folder = Left(buffer, Len(buffer) - 1)
 &nbsp; &nbsp;If folder <> vbNullString Then 'user selected OK
 &nbsp; &nbsp; &nbsp; &nbsp;If Right(folder, 1) <> "\" Then folder = folder + "\"
 &nbsp; &nbsp;Path = Mid(folder, 1, Len(folder) - 1)
 &nbsp; &nbsp;txtRemotePath.Text = Mid(Path, InStrRev(Path, "\") + 1)

End If
End Sub



All times are GMT +1. The time now is 09:33 PM.

Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.