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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtain folder pathname from BrowseForFolder interface 2

Status
Not open for further replies.

jasonp45

Programmer
Aug 23, 2001
212
US
Running a VBScript on my XP machine (not associated with any Web stuff) this works fine in bringing up a folder-browser and reporting the folder's title:

Code:
Dim oAppShell 'as Shell.Application
Dim oFolder 'as Folder
Set oAppShell = CreateObject("Shell.Application")
Set oFolder = oAppShell.BrowseForFolder(0,"Test",0)
MsgBox oFolder.Title

However what I need is the folder's _path_, and I can't seem to find a way to do this. (
The Folder object doesn't implement a 'Name' property...the FolderItem object does, and I could probably work from that, but for this project the selected folder is likely to be empty and the FolderItem(s) doesn't seem to work in that case.
 
Try this:

Dim oAppShell 'as Shell.Application
Dim oFolder 'as Folder
Dim oParent
Dim oFI
Set oAppShell = CreateObject("Shell.Application")
Set oFolder = oAppShell.BrowseForFolder(0,"Test",0)
MsgBox oFolder.Title
Set oParent = oFolder.ParentFolder
Set oFI = oParent.ParseName(oFolder.Title)
MsgBox oFI.Path

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Code:
...
Set oFolder = oAppShell.BrowseForFolder(0,"Test",0)
If (Not oFolder Is Nothing) Then
  MsgBox oFolder.Items.Item.Path
End If
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Nice. I knew there must be a way to do it with the initial object I just got tired of looking for it. :)

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks very much - works like a charm! I needed to be able to allow drives to be selected as well which doesn't work with the Parent object...below is the final code I came up with:

Code:
Private Sub User_SetTargetFolder()
  Dim oAppShell 'as Shell.Application
  Dim oFolder 'as Folder
  Dim oParent 'as Folder.Parent
  Dim oFolderItem 'as FolderItem
  Set oAppShell = CreateObject("Shell.Application")
  Set oFolder = oAppShell.BrowseForFolder(0, "Select Target Drive or Folder", 0)
  If InStr(oFolder.Title, ":") > 0 Then 'Drive selected rather than folder
    Target = Mid(oFolder.Title, InStr(oFolder.Title, ":") - 1, 2) & "\" 
  Else
    Set oParent = oFolder.ParentFolder
    Set oFolderItem = oParent.ParseName(oFolder.Title)
    Target = oFolderItem.Path & "\"
  End If
  MsgBox Target    
End Sub
[\code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top