Mombu the Microsoft Forum

Mombu the Microsoft Forum > Microsoft > Windows 2003 Server (TECHNET) > Browse for Folder
REGISTER NOW! Mark Forums Read




Reply
 
Thread Tools Display Modes
1 18th April 20:27
d. malaguti
External User
 
Posts: 1
Default Browse for Folder



I am opening a "Browse for Folder" dialog using the BrowseForFolder
method of the Shell object. Is there any way to get this dialog to open
to a particular folder, while still allowing access to the entire file
system? This dialog will be accessed frequently and users will mostly
be selecting folders in the same area of the file system, so I'd like to
save the trouble of having to drill down each time. They may need to
move higher in the tree at times, however, so I can't just set the root
folder.

- D.
  Reply With Quote
SPONSORED LINKS BY GOOGLE

 


2 18th April 20:27
fosco
External User
 
Posts: 1
Default Browse for Folder



"D. Malaguti"

here a full example and it works with ALL os's


' Use BrowseForFolder to return file name...
' by: Joe Earnest, posted on vbScript ng, 09Jan03
'
' 11Jan03: added comments by jw (sorry Joe, couldn't resist)
' Note(jw): Haven't seen this particular edition of BFF before.
' For one thing, it comes with a textbox (i.e., an edit control)
' just under the "title" (i.e., a label). You may type any
' filespec or folder name you wish directly into the textbox.
' For another thing, the "TreeView" control is set up to show
' individual files as well as folders, and Joe's code shows
' how to retrieve the filename...
' --- end of discussion --------------------------
Option Explicit
'
Dim oSHApp : Set oSHApp= CreateObject("Shell.Application")
'
' Function Template:
' BrowseForFolder(Hwnd As Long, Title As String,
' Options As Long, [RootFolder]) As Folder
'
' Browsing for directory constants (from shlobj.h)...
Const BIF_RETURNONLYFSDIRS = &H0001 ' For finding a folder to start document searching
Const BIF_DONTGOBELOWDOMAIN = &H0002 ' For starting the Find Computer
Const BIF_STATUSTEXT = &H0004
Const BIF_RETURNFSANCESTORS = &H0008
Const BIF_EDITBOX = &H0010
Const BIF_VALIDATE = &H0020 ' insist on valid result (or CANCEL)
Const BIF_NEWDIALOGSTYLE = &H0040 ' (Version 5.0). use the new user interface.
' (you get a larger dialog box, with several new capabilities - see msdn)...
'
Const BIF_BROWSEFORCOMPUTER = &H1000 ' Browsing for Computers
Const BIF_BROWSEFORPRINTER = &H2000 ' Browsing for Printers
Const BIF_BROWSEINCLUDEFILES = &H4000 ' Browsing for Everything
'
' Shell Special Folder constants...
Const ssfDESKTOP = 0
Const ssfPROGRAMS = 2
Const ssfCONTROLS = 3
Const ssfPRINTERS = 4
Const ssfPERSONAL = 5
Const ssfFAVORITES = 6
Const ssfSTARTUP = 7
Const ssfRECENT = 8
Const ssfSENDTO = 9
Const ssfBITBUCKET = 10 ' a.k.a. recycle bin
Const ssfSTARTMENU = 11
Const ssfDESKTOPDIRECTORY = 16 ' (&H10)
Const ssfDRIVES = 17 ' (&H11) MyComputer Drives
Const ssfNETWORK = 18 ' (&H12)
Const ssfNETHOOD = 19 ' (&H13)
Const ssfFONTS = 20 ' (&H14)
Const ssfTEMPLATES = 21 ' (&H15)
Const ssfCOMMONSTARTMENU = 22 ' (&H16)
Const ssfCOMMONPROGRAMS = 23 ' (&H17)
Const ssfCOMMONSTARTUP = 24 ' (&H18)
Const ssfCOMMONDESKTOPDIR = 25 ' (&H19)
Const ssfAPPDATA = 26 ' (&H1A)
Const ssfPRINTHOOD = 27 ' (&H1B)
Const ssfLOCALAPPDATA = 28 ' (&H1C)
Const ssfALTSTARTUP = 29 ' (&H1D)
Const ssfCOMMONALTSTARTUP = 30 ' (&H1E)
Const ssfCOMMONFAVORITES = 31 ' (&H1F)
Const ssfINTERNETCACHE = 32 ' (&H20)
Const ssfCOOKIES = 33 ' (&H21)
Const ssfHISTORY = 34 ' (&H22)
Const ssfCOMMONAPPDATA = 35 ' (&H23)
Const ssfWINDOWS = 36 ' (&H24)
Const ssfSYSTEM = 37 ' (&H25)
Const ssfPROGRAMFILES = 38 ' (&H26)
Const ssfMYPICTURES = 39 ' (&H27)
Const ssfPROFILE = 40 ' (&H28)
Const ssfSYSTEMx86 = 41 ' (&H29)
Const ssfPROGRAMFILESx86 = 48 ' (&H30)
'
Dim oFolder ' as folder object
Const hDesktop = 0 ' use desktop as parent window...
Const sTitle = "Select a File or Folder... "
Dim vOptions : vOptions = BIF_BROWSEINCLUDEFILES _
Or BIF_NEWDIALOGSTYLE Or BIF_VALIDATE Or BIF_EDITBOX

Dim vRootFolder : vRootFolder = ssfDRIVES
'
Dim sResult ' as string
' --- end of constants and declarations ----------

' will return a (valid) file or folder...
'ORIGINAL
Set oFolder = oSHApp.BrowseForFolder(hDesktop, sTitle, vOptions, vRootFolder)

' Start nenu
Set oFolder = oSHApp.BrowseForFolder(hDesktop, sTitle, vOptions, ssfSTARTMENU)

' o.k., all the hard work is over, now interpret the results...
If (oFolder Is Nothing) then MsgBox("You clicked CANCEL") : WScript.Quit

' note: we insisted on a valid result, so if it's not nothing
' then the result must be a folder or file. BUT STILL, even if
' a file is returned the TypeName function will say folder object...
If (UCase(TypeName(oFolder)) = "FOLDER") Then ' verify folder
On Error Resume Next
sResult = oFolder.ParentFolder.ParseName(oFolder.Title).Path
If Err Then Err.Clear : sResult = oFolder.Title ' has no parent
On Error GoTo 0 ' turn off error processing
MsgBox("BFF returned: " & sResult)

Else ' something went wrong, it should have been "FOLDER"...
MsgBox("Unexpected result, BFF returned: " & oFolder.Title)
End If


--
Fosco
  Reply With Quote
3 18th April 20:27
todd vargo
External User
 
Posts: 1
Default Browse for Folder


Please reread the OP's question. AFAIK, the BFF window does not have
provision to open with a default path pre selected below a specified root.

i.e. It can not open ssfDRIVES with say C:\Windows\System already selected.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
  Reply With Quote
4 18th April 20:27
richard mueller [mvp]
External User
 
Posts: 1
Default Browse for Folder


The 4th parameter of the BrowseForFolder method can be a path and the dialog
will open at that path. The user will be able to navigate down from there,
but not higher. See this link:

http://msdn.microsoft.com/library/de...eforfolder.asp

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
  Reply With Quote
5 18th April 20:27
fosco
External User
 
Posts: 1
Default Browse for Folder


Todd Vargo:


ahh , Ok ... sorry


--
Fosco
  Reply With Quote
6 18th April 20:27
todd vargo
External User
 
Posts: 1
Default Browse for Folder


You're preaching to the choir. The OP already knows this lesson but was
hoping someone knew of a work around for that limitation. <shrug>

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
  Reply With Quote
7 18th April 20:27
alexander mueller
External User
 
Posts: 1
Default Browse for Folder


08.04.2007 06:42, D. Malaguti schrieb:


Not possible with scripting. You can set the root-folder
but done so, you cannot choose a folder above.

If you use Win32-API and SHBrowseForFolder (+ another dev-
environment) you could set a BrowseCallbackProc-function as
arg of the BROWSEINFO param, which allows customization of
the dialog in some ways, for example preselection of the
initial folder (using SendMessage).
But that's nothing to be done in scripting.

http://msdn.microsoft.com/library/en...llbackproc.asp

MfG,
Alex
  Reply With Quote
8 18th April 20:28
dmala
External User
 
Posts: 1
Default Browse for Folder


That's what I suspected, but I figured it was worth asking.

Heh, I'd say that's definitely beyond the scope of what I'm doing here.

Thanks for the replies.

-D.
  Reply With Quote
9 26th April 04:13
asdf
External User
 
Posts: 1
Default Browse for Folder


Sounds like the end of explorer,
found nothing.

Only dead bodies.
  Reply With Quote
SPONSORED LINKS BY GOOGLE

 


Reply


Thread Tools
Display Modes







Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
Also visit Ogoun the Usenet Archive
666