[AccessD] Selecting a directory

Stuart McLachlan stuart at lexacorp.com.pg
Tue Feb 8 22:21:03 CST 2005


On 8 Feb 2005 at 22:36, John W. Colby wrote:

> I have used the ADH FindFile module and function for ages.  However I also
> need to select a directory (to copy a file to for example) and the ADH code
> only allows selecting a file, not a dir.  Is there any way to cause that
> code to select a directory?  Is there another module / function to use the
> fileFind dialog to select a directory?
> 

Here's the necessary bits to use the SHBrowseForFolder API call:

Public Declare Function SHBrowseForFolder Lib "shell32.dll" _
   Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Public 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

'BROWSEINFO.ulFlags values:
Public Const BIF_RETURNONLYFSDIRS = &H1      'Only file system directories
Public Const BIF_DONTGOBELOWDOMAIN = &H2     'No network folders below 
domain level
Public Const BIF_STATUSTEXT = &H4            'Includes status area in the 
dialog (for callback)
Public Const BIF_RETURNFSANCESTORS = &H8     'Only returns file system 
ancestors
Public Const BIF_EDITBOX = &H10              'Allows user to rename 
selection
Public Const BIF_VALIDATE = &H20             'Insist on valid editbox 
result (or CANCEL)
Public Const BIF_BROWSEFORCOMPUTER = &H1000  'Only returns computers.
Public Const BIF_BROWSEFORPRINTER = &H2000   'Only returns printers.
Public Const BIF_BROWSEINCLUDEFILES = &H4000 'Browse for everything
Public Const MAX_PATH = 260



Private Sub btnBrowseForFolder_Click()
  Dim pidl As Long
  Dim BI As BROWSEINFO
  Dim sPath As String
  Dim pos As Integer
 
  'Fill BROWSEINFO structure data
   With BI
      .hOwner = 0
      .pidlRoot = 0
      .lpszTitle = "Browsing"
      .ulFlags = 1
      .pszDisplayName = Space$(260)
   End With
  
  'show dialog returning pidl to selected item
   pidl = SHBrowseForFolder(BI)
 
  'if pidl is valid, parse & return the user's selection
   sPath = Space$(260)
    
   If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
   
     'SHGetPathFromIDList returns the absolute
     'path to the selected item. No path is returned for virtual folders.
      pos = InStr(sPath, Chr$(0))
      If pos Then Text1 = Left(sPath, pos - 1)
   Else:
     Text1 = "Problem"
   End If
 'free the pidl
   Call CoTaskMemFree(pidl)
        
End Sub

-- 
Stuart





More information about the AccessD mailing list