Discussion:
Going up the tree with BrowseForFolder?
(too old to reply)
Dave "Crash" Dummy
2014-09-04 15:44:36 UTC
Permalink
I am using BrowseForFolder to select a subdirectory starting at
a particular directory. This works fine, but I would like the option of
stepping back up the tree to the parent directory of the starting
directory. For example, if I start at d:\level1\level2 using this code,

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0,"Select",0,"d:\level1\level2")

Is there an option that allows me to step back to d:\level1 and select
from there?
--
Crash

A line in the sand doesn't mean much if it disappears at high tide.
GS
2014-09-04 17:16:12 UTC
Permalink
Post by Dave "Crash" Dummy
I am using BrowseForFolder to select a subdirectory starting at
a particular directory. This works fine, but I would like the option of
stepping back up the tree to the parent directory of the starting
directory. For example, if I start at d:\level1\level2 using this code,
Set objShell = CreateObject("Shell.Application")
Set objFolder =
objShell.BrowseForFolder(0,"Select",0,"d:\level1\level2")
Is there an option that allows me to step back to d:\level1 and
select from there?
objFolder.ParentFolder
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Dave "Crash" Dummy
2014-09-04 18:29:04 UTC
Permalink
Post by GS
Post by Dave "Crash" Dummy
I am using BrowseForFolder to select a subdirectory starting at
a particular directory. This works fine, but I would like the option of
stepping back up the tree to the parent directory of the starting
directory. For example, if I start at d:\level1\level2 using this code,
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0,"Select",0,"d:\level1\level2")
Is there an option that allows me to step back to d:\level1 and select
from there?
objFolder.ParentFolder
Yes, that allows me to find the parent folder after one is selected, but
it does not affect the BrowseForFolder operation while it is open. I
want to go to the parent folder of the current root of the
BrowseForFolder function while it is open.
--
Crash

A line in the sand doesn't mean much if it disappears at high tide.
GS
2014-09-04 18:59:04 UTC
Permalink
Post by Dave "Crash" Dummy
Post by GS
Post by Dave "Crash" Dummy
I am using BrowseForFolder to select a subdirectory starting at
a particular directory. This works fine, but I would like the option of
stepping back up the tree to the parent directory of the starting
directory. For example, if I start at d:\level1\level2 using this code,
Set objShell = CreateObject("Shell.Application")
Set objFolder =
objShell.BrowseForFolder(0,"Select",0,"d:\level1\level2")
Is there an option that allows me to step back to d:\level1 and
select from there?
objFolder.ParentFolder
Yes, that allows me to find the parent folder after one is selected, but
it does not affect the BrowseForFolder operation while it is open. I
want to go to the parent folder of the current root of the
BrowseForFolder function while it is open.
When BrowseForFolder opens.., it's all manual navigation from that
point. Optionally, though, you can pass the start folder to be set as
the top level folder when the dialog opens. Is this what you want?
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2014-09-04 19:02:37 UTC
Permalink
Post by Dave "Crash" Dummy
Is there an option that allows me to step back to d:\level1 and
select from there?
Nope!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Dave "Crash" Dummy
2014-09-04 21:07:23 UTC
Permalink
Post by Dave "Crash" Dummy
Is there an option that allows me to step back to d:\level1 and
select from there?
Nope!
That's what I feared, but I had to ask.
--
Crash

Give a man a fish, and he eats for a day.
Teach a man to fish, and his wife hates you for a lifetime.
GS
2014-09-04 19:17:13 UTC
Permalink
You might be better of using the common dialog, but that's problematic
on systems that don't have it in ocx, but dll only, and vice versa. You
could check for existence based on OS version via an If...Then
construct so you get the OS's version (classic 'up 1 level or the newer
address bar path config). There's likely lots of code samples floating
around for both!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Dave "Crash" Dummy
2014-09-04 20:58:05 UTC
Permalink
Post by GS
You might be better of using the common dialog, but that's problematic
on systems that don't have it in ocx, but dll only, and vice versa. You
could check for existence based on OS version via an If...Then construct
so you get the OS's version (classic 'up 1 level or the newer address
bar path config). There's likely lots of code samples floating around
for both!
"Up one level" is exactly what I want. What OCX/DLL filename should I
look for?
--
Crash

I'm smart enough to admit my ignorance.
Dave "Crash" Dummy
2014-09-04 21:05:17 UTC
Permalink
Post by Dave "Crash" Dummy
Post by GS
You might be better of using the common dialog, but that's
problematic on systems that don't have it in ocx, but dll only, and
vice versa. You could check for existence based on OS version via
an If...Then construct so you get the OS's version (classic 'up 1
level or the newer address bar path config). There's likely lots of
code samples floating around for both!
"Up one level" is exactly what I want. What OCX/DLL filename should I
look for?
Okay. I don't have commdlg.dll or .ocx in my Windows 7 SP1 x64 system.
Maybe I have to have Office or something installed.
--
Crash

One man's weed is another man's wildflower.
GS
2014-09-05 00:30:08 UTC
Permalink
Post by Dave "Crash" Dummy
Post by Dave "Crash" Dummy
Post by GS
You might be better of using the common dialog, but that's
problematic on systems that don't have it in ocx, but dll only, and
vice versa. You could check for existence based on OS version via
an If...Then construct so you get the OS's version (classic 'up 1
level or the newer address bar path config). There's likely lots of
code samples floating around for both!
"Up one level" is exactly what I want. What OCX/DLL filename should I
look for?
Okay. I don't have commdlg.dll or .ocx in my Windows 7 SP1 x64
system.
Maybe I have to have Office or something installed.
On my Win7/8 machines it's 'comdlg32.dll' under 'SysWow64'.
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Dave "Crash" Dummy
2014-09-05 01:00:09 UTC
Permalink
Post by GS
Post by Dave "Crash" Dummy
Post by Dave "Crash" Dummy
Post by GS
You might be better of using the common dialog, but that's
problematic on systems that don't have it in ocx, but dll only, and
vice versa. You could check for existence based on OS version via
an If...Then construct so you get the OS's version (classic 'up 1
level or the newer address bar path config). There's likely lots of
code samples floating around for both!
"Up one level" is exactly what I want. What OCX/DLL filename should I
look for?
Okay. I don't have commdlg.dll or .ocx in my Windows 7 SP1 x64 system.
Maybe I have to have Office or something installed.
On my Win7/8 machines it's 'comdlg32.dll' under 'SysWow64'.
Okay, I have that, but I don't know how to use it in VBScript.
--
Crash

Dogs have masters. Cats have attendants.
GS
2014-09-05 01:17:41 UTC
Permalink
Post by Dave "Crash" Dummy
Post by GS
Post by Dave "Crash" Dummy
Post by Dave "Crash" Dummy
Post by GS
You might be better of using the common dialog, but that's
problematic on systems that don't have it in ocx, but dll only, and
vice versa. You could check for existence based on OS version via
an If...Then construct so you get the OS's version (classic 'up 1
level or the newer address bar path config). There's likely lots of
code samples floating around for both!
"Up one level" is exactly what I want. What OCX/DLL filename should I
look for?
Okay. I don't have commdlg.dll or .ocx in my Windows 7 SP1 x64 system.
Maybe I have to have Office or something installed.
On my Win7/8 machines it's 'comdlg32.dll' under 'SysWow64'.
Okay, I have that, but I don't know how to use it in VBScript.
Well that won't matter because it appears to use the same
BrowseForFolder dialog according to what I found and tested from
here...

http://www.thevbzone.com/modCOMDLG32.bas

..which is a VB[A} implementation that I was hoping was a solution. Now
that I think of it.., Windows does use that dialog as its folder
picker. Hmm, I wonder if you could use the FileOpen dialog and just
filter for the path...
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2014-09-05 02:27:37 UTC
Permalink
Hmm, I wonder if you could use the FileOpen dialog and just filter
for the path...
This allows using a dummy filename...


Sub PickFolder()
Dim sf$, sp$, lRet&
sf = "MyFile"
'SaveAs
lRet = CD_ShowOpen_Save(Application.hWnd, , sf, sp, , , , , False)
Debug.Print Mid(sf, 1, Len(sf) - Len(sp))
End Sub

..and returns the path like so...

C:\Users\Garry\

..even if the user selects a filename or changes the dummy filename.

This requires user to select an existing fiename, and so won't work
with empty folders...

Sub PickFolder()
Dim sf$, sp$, lRet&
sf = "MyFile"
'Open
lRet = CD_ShowOpen_Save(Application.hWnd, , sf, sp)
Debug.Print Mid(sf, 1, Len(sf) - Len(sp))
End Sub

Normally, I use the following and specify 'Drives' as the top level
folder so users must drill down...


Function GetDirectory$(Optional OpenAt, Optional MSG$)
' Returns the path of a user selected folder
' Note: By default, dialog opens at 'Desktop'
' Args:
' OpenAt Optional: Path to the dialog's top level folder
' Msg Optional: The dialog's title

If MSG = "" Then MSG = "Please choose a folder"
On Error Resume Next '//if user cancels
GetDirectory = CreateObject("Shell.Application").BrowseForFolder(0,
MSG, &H40 Or &H10, OpenAt).Self.Path
End Function 'GetDirectory()

..and use it like this...

sPath = GetDirectory(SpclFldrs.osDrvs)
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"

..where SpclFldrs is an enum of all the special folder constants and
osDrvs=17. (Note that the trailing backslash will be missing and so
requires appending)

Otherwise I just pass the top level path under which I want users to
search!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2014-09-05 02:33:17 UTC
Permalink
This code...
Post by GS
sPath = GetDirectory(SpclFldrs.osDrvs)
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
usually includes...

If sPath = "" Then GoTo NormalExit '//user cancel

..before the last line gets executed.
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2014-09-05 04:58:50 UTC
Permalink
I meant to mention that the 2nd last arg is where you set the folder to
start in, but I assumed you'd figure that out reading the args list!<g>
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Mayayana
2014-09-05 02:29:58 UTC
Permalink
The comdlg OCX is licensed. It's not generally usable.
While it wraps comdlg32.dll, that library doesn't have
BrowseForFolder. The original function is SHBrowseForFolder,
in shell32.dll. Shell.Application is a wrapper for that.
In both cases, the option is to set an upper level restriction.
There isn't a function to set a folder to start with, like
can be done with FileOpen.
Loading...