PDA

Click to See Complete Forum and Search --> : browsing for folder


Howard Stern
Nov 1st, 1999, 10:25 PM
i want to allow a user to browse for a directory, not a file. i think the common dialog must return a file, how would i go about selecting and returning a directory?

blofeld3
Nov 1st, 1999, 10:57 PM
put a directory list box on your form and read the results on a label or something (I think this will work...I picked the code out of a bigger block).

Private Sub Dirdirectory_Change()
Dim spath
spath = Dirdirectory.Path

lbldirname.Caption = Dirdirectory.Path 'update drive label

smalig
Nov 2nd, 1999, 12:01 AM
Look here http://smalig.tripod.com/vb/079901.html

------------------
smalig
smalig@hotmail.com
smalig.tripod.com (http://smalig.tripod.com)

Serge
Nov 2nd, 1999, 12:04 AM
Sure thing:


Private Type BROWSEINFO 'bi
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Const BIF_RETURNONLYFSDIRS = &H1

Public Function ShowFolderDialog(pHwnd As Long) As String
Dim biStruct As BROWSEINFO
Dim lPidl As Long
Dim lRet As Long
Dim intPos As Integer
Dim strPath As String

biStruct.hOwner = pHwnd
biStruct.pidlRoot = 0
biStruct.lpszTitle = "Select Folder"
biStruct.ulFlags = BIF_RETURNONLYFSDIRS
lPidl = SHBrowseForFolder(biStruct)
strPath = Space(512)
lRet = SHGetPathFromIDList(ByVal lPidl, ByVal strPath)
If lRet Then
intPos = InStr(strPath, vbNullChar)
ShowFolderDialog = Left(strPath, intPos - 1)
End If
End Function




Usage: Result = ShowFolderDialog(OwnedWindowHwnd As Long)

Example: MsgBox ShowFolderDialog(Me.hWnd)

Regards,

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com

Aaron Young
Nov 2nd, 1999, 03:03 AM
If you're already using the CommonDialog elsewhere in your application an don't want to add the extra code for the Folder Browser, a quick modification to the CommonDialog Properties can yield satisfactory results..

Private Sub Command1_Click()
Dim sDir As String
With CommonDialog1
.Flags = cdlOFNNoValidate
.FileName = "*"
.ShowOpen
sDir = Left(.FileName, Len(.FileName) - Len(.FileTitle) - 1)
End With
Debug.Print sDir 'Display Select Folder Path
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net