Solved

Selecting a directory.

Posted on 2000-03-13
6
169 Views
Last Modified: 2010-05-02
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
Comment
Question by:egunn
  • 3
  • 2
6 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 50 total points
ID: 2612273
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2612305
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
 

Author Comment

by:egunn
ID: 2612315
Sorry EDDYKT's answer is more elegant.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:egunn
ID: 2612323
Brilliant , I don't suppose you know how to do and FTP directory as well do you. More points in it.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 2612414
For ftp directory, you can either use wininet.dll or msinet.ocx to build your own directory dialog
0
 

Author Comment

by:egunn
ID: 2612427
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now