Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select a folder only 1

Status
Not open for further replies.

tar28un

Technical User
Nov 29, 2005
58
GB
is there a way of getting just the path of the file this way, without the file name in it?
E.G. if i open
C:\Windows\Wini.ini
can i get the program to read just
C:\Windows
from that?
If I add a common dialog box it will let the user select the file as well, but I want the user to only select the folder
 
TheString="C:\Windows\Wini.ini"

ThePath=Left(TheString, InStrRev(TheString, "\") - 1)

?ThePath
C:\Windows
 
Hi there,

Thanks for the reply. What if the user did not select any file and only select the directory ,then this code will take the path to one directory behind. Do you have any idea on how to use Directory list box and whether it is of any help or not.
 
Here a function you can use:
Code:
Function PickFolder(strStartDir As Variant) As String
    Dim SA As Object, F As Object
    Set SA = CreateObject("Shell.Application")
    Set F = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
    If (Not F Is Nothing) Then
        PickFolder = F.Items.Item.path
    End If
    Set F = Nothing
    Set SA = Nothing
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top