Solved

Selecting a directory.

Posted on 2000-03-13
6
173 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 68
Automatic Email Reminder 4 72
VBA - If Bookmark = "XXBOOKMARKXX" then 15 51
Help with Classic ASP - Parameterizing Query 16 20
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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