[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

Selecting a directory.

Does anybody know of an easy way to select just a directory using the common dialog control? Or perhaps another way that doesn't involve writing a form with a directory selector on it.
0
egunn
Asked:
egunn
  • 3
  • 2
1 Solution
 
EDDYKTCommented:
Option Explicit
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 Type BROWSEINFO
    HwndOwner 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 Sub Command1_Click()
    Dim Info As BROWSEINFO
    Dim PID As Long, Path As String, Tmp As String
    Dim localpath As String
     
    Info.HwndOwner = Me.hWnd
    Info.PidlRoot = &H0
    Info.LpszTitle = "Select File Path:"
    Info.UlFlags = &H1
    PID = SHBrowseForFolder(Info)
    Path = Space$(512)
    If (SHGetPathFromIDList(PID, Path)) Then localpath = Left$(Path, InStr(Path, Chr$(0)) - 1)
End Sub

If cancel is pressed, localpath is ""


0
 
mcriderCommented:
Here you go!


Dim iVal As Long
Dim SelectedPath As String

On Error Resume Next
With CommonDialog1
    .filename = "PATH"
    .Flags = cdlOFNExplorer
    .CancelError = True
    .Action = 1
    If Err = 0 Then
        For iVal = Len(.filename) To 1 Step -1
            If Mid$(.filename, iVal, 1) = "\" Then
                SelectedPath = Left$(.filename, iVal - 1)
                Exit For
            End If
        Next iVal
    End If
End With
MsgBox "You Selected:  " + SelectedPath


Cheers!®©
0
 
egunnAuthor Commented:
Sorry EDDYKT's answer is more elegant.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
egunnAuthor Commented:
Brilliant , I don't suppose you know how to do and FTP directory as well do you. More points in it.
0
 
EDDYKTCommented:
For ftp directory, you can either use wininet.dll or msinet.ocx to build your own directory dialog
0
 
egunnAuthor Commented:
Thanks, I thought about that but it just seems like a lot of hassel to go to. I've posted another question asking this hopefully somebody's already done it and will let me have the code.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now