Alternately, if there is no such beast, is it possible to
determine the last directory that the FileOpen common
dialog (MSComDlg.CommonDialog or UserAccounts.CommonDialog)
was showing?
Thanks,
Csaba Gabor from Vienna
"Csaba Gabor" <cs...@z6.com> wrote in message
news:uG8l$ZgRFH...@TK2MSFTNGP15.phx.gbl...
BrowseForFolder
----
set oShell= createobject("shell.application")
sMsg= "Select a Folder"
cBits= 1
xRoot= 17
on error resume next
dim oBFF: set oBFF= oShell.browseForFolder(0, sMsg, cBits, xRoot)
if err then err.clear: wscript.quit
on error goto 0
if not isobject(oBFF) then wscript.quit
if not (lcase(left(trim(typename(oBFF)), 6))="folder") then wscript.quit
'WinXP+ only (Win2k ?)
msgbox oBFF.self.path
----
'for any version of Windows in place of the above line
on error resume next
sFolder= oBFF.parentFolder.parseName(oBFF.title).path
fErr= cbool(err)
on error goto 0
if fErr then
sFolder= oBFF.title
iColon= instr(sFolder, ":")
if (iColon<2) then wscript.quit
sFolder= ucase(mid(sFolder, iColon -1, 2)) & "\"
end if
----
The usefulness of the Shell.BrowseForFolder method seems to have diminished
with each new version of Windows. The WinXp version of this method pops up
a resizable explorer-style dialog box that will assume the selected WinXp
theme or dialog style setting, at a set location in the approximate center
of the screen. Other versions of Windows pop up a simpler, non-resizable
dialog in the upper left corner of the screen. Different versions have
different option codes available, making it difficult to use anything but
the most basic operations across multiple Windows versions. Even though
documented as available, the method can no longer be used for file selection
in WinXp and has problems selecting root directory files in Win2k. MS has
apparently noted that the dialog should no longer be used for files. In
more than one version, edit box input cannot be validated. In addition, the
object does not appear to be fully implemented on WinXp. A number of
documented options (some listed as specifically available to WinXp) do not
appear to work at all, at least for purposes of scripting. Nevertheless,
the object remains useful for its basic folder operation.
If the dialog is dismissed, or if the user attempts to specify a
non-existent folder in the edit box, the object is set to Nothing.
Otherwise, it is set as a folder object. The folder pathname can be
extracted using the Self.Path property in WinShell5+ versions of Windows.
In other versions of Windows, the ParseName property can be used. The
ParseName property, however, generates a runtime error for a drive (root
folder), so it must be error-trapped, and the title must be searched for the
drive letter specifier, if root folder selection is permitted and a runtime
error is generated.
The message option accepts a text message string of no more than two
(non-WinXp) or three (WinXp) short lines to display at the top of the dialog
box. The root folder option specifies a dialog root folder for subfolder
selection as either a folder pathname string or a Shell special folder
integer code. The most useful special folder integer code for this dialog
is 17, which specifies the My Computer virtual folder with all drives
displayed. The object method defaults to the Desktop (code 0 ), if omitted,
or if a non-existing folder is specified.
The following are the generally useful long integer bitwise code flags for
dialog operation:
&H0001 1 Only returns file system folders. Will not select a virtual
folder.
&H0002 2 Does not include network folders below the domain level.
&H0010 16 Displays an edit box for user input specification.
&H0020 32 Validates the user specification in the edit box, if implemented.
This option does not appear to work as documented on all versions of
Windows.
&H0040 64 Displays a "new style" dialog box, at least for Win2k. This
option will be ignored, if specified for WinXp, and may be ignored on
versions of Windows other than Win2k.
&H0100 256 Displays a user "hint" in a WinXp-style dialog, if the edit box
is not implemented. Available only for WinXp. This option is ignored, if
an edit box is implemented.
&H0200 512 Suppresses display of the New Folder button in a WinXp-style
dialog. Available only for WinXp.
&H04000 16384 Displays files as well as folders, and allows file selection.
The files will display properly in all versions. With Win2k, however, a
runtime error is generated if a root directory file is selected, and with
WinXp, a runtime error is generated if any file is selected.
Joe Earnest
> set oShell= createobject("shell.application")
...
> dim oBFF: set oBFF= oShell.browseForFolder(0, sMsg, cBits, xRoot)
Wow Joe! Thanks for an incredibly useful and thorough post.
I've taken what you shared and rolled it into a (PHP) function I
can call from my Command Line Interface (CLI) version of PHP
(only tested on my WinXP system).
Regards,
Csaba Gabor from Vienna
"Csaba Gabor" <cs...@z6.com> wrote in message
news:O8hP9tBS...@TK2MSFTNGP12.phx.gbl...
...
> Wow Joe! Thanks for an incredibly useful and thorough post.
> I've taken what you shared and rolled it into a (PHP) function I
> can call from my Command Line Interface (CLI) version of PHP
> (only tested on my WinXP system).
>
> Regards,
> Csaba Gabor from Vienna
Your welcome.
Regards,
Joe Earnest
I wasn't clear based on your explaination.
[snipped]
"Anonymous" <Anon...@discussions.microsoft.com> wrote in message
news:0B41E154-7B51-4B31...@microsoft.com...
> Can you clarify if this is an implementation of the (what I would call)
> simple BrowseForFolder dialog, with the tree view of folders, and three
> buttons at the bottom (OK, Cancel, and New Folder), ... or an
> implementation
> of a variation on the CommonDialog, such as the Open File dialog you get
> when
> you click Open File in vs.Net 2003, with large icons in a column on the
> left
> (DeskTop, Favorites, My Documents, etc.), toolbar icons across the top to
> the
> right (Up, Create New, View, Tools, etc.), and folder names (and depending
> on
> the view selected), possible a few other columns?
>
> I wasn't clear based on your explaination.
This is the traditional BrowseForFolder dialog. The discussion was oriented
toward its current status for Windows XP.
To the best of my knowledge, the MsComDlg.CommonDialog, itself, as well as
the MS Java VM implementation of the CommonDialog, and the few Windows OS
version-specific implementations of the CommonDialog
(UserAccounts.CommonDialog, SAFRCFileDlg.FileSave, etc.), are all
file-oriented, and the only way to select a folder is to select or a file
from that folder, which is awkward. (Of course, the CommonDialog, itself,
has a print, color, font and help dialog option, but no folder-only option.)
You can specify no file validation and return a wildcard user-specification
from the selected folder -- but again, very awkward.
You can construct an HTML window listing of folders using basic HTML Select
control dropbox/listbox techniques, which allow single or multiple
selections, but no tree, unless you set up a DHTML multiple listbox
pseudo-"tree".
I've seen posts discussing the use of an HTML Windows Explorer tree, but,
(as best I recall) there is a problem in getting a selection return from the
window back to the initiating script. Not sure about this last alternative.
Joe Earnest
[snipped again]
"Anonymous" <Anon...@discussions.microsoft.com> wrote in message
news:0B41E154-7B51-4B31...@microsoft.com...
> Can you clarify if this is an implementation of the (what I would call)
> simple BrowseForFolder dialog, with the tree view of folders, and three
> buttons at the bottom (OK, Cancel, and New Folder), ... or an
> implementation
> of a variation on the CommonDialog, such as the Open File dialog you get
> when
> you click Open File in vs.Net 2003, with large icons in a column on the
> left
> (DeskTop, Favorites, My Documents, etc.), toolbar icons across the top to
> the
> right (Up, Create New, View, Tools, etc.), and folder names (and depending
> on
> the view selected), possible a few other columns?
>
> I wasn't clear based on your explaination.
In addition to the last response, I should have added --
As discussed in my original post, in its XP-incarnation, the "traditional"
BrowseForFolder dialog assumes the Windows XP styles and skins, but no large
icons down the side, etc. The script-accessible MsComDlg.CommonDialog,
itself, and its MS Java VM implementation, do not even do this -- they
retain the "old-fashioned" simple dialog box. The Windows XP/2003
version-specific implementations of the CommonDialog
(UserAccounts.CommonDialog, SAFRCFileDlg.FileSave, etc.), do have the full
XP styling, with large icons, etc., at least for Windows XP.
If style is the issue, try the originally posted script and see what you
get.
Joe Earnest