Hi,
gibts doch massig im inet
Quelle
'********************************************************
' FolderSelectDialog.vbs
' Alan Kaplan alan at akaplan dot com 12-15-2005
' after getting tired of reading it will not work...
' Based in part on FileSelectDialog.vbs by Gunter Born
' Kaplan added handling of special folders
' Tested okay with XP and 2000
' Uses the shell browseforfolder method to select a folder
'********************************************************
' Flags for the options parameter
Const BIF_returnonlyfsdirs = &H1 'Don't want no steenkin' filenames
Const BIF_ShowAllObjects = &H8 'ReturnFSAncestors. This will give you
' typical root view XP has My Computer, My Network Places not seen on 2000
Const BIF_editbox = &H10 'Show active selection, allows manual
' input
Private Sub Command1_Click()
Dim strFolder, sRoot
sRoot = "c:\Drivers" ' ROOOOOOOOOT
strFolder = BrowseForFolder("Choose a folder, then click OK:", _
BIF_returnonlyfsdirs + BIF_editbox + BIF_ShowAllObjects, sRoot)
If Len(strFolder) > 0 Then
MsgBox strFolder, vbOKOnly, "Selected Folder"
End If
End Sub
Function BrowseForFolder(title, flag, dir) As String
On Error Resume Next ' If user clicks cancel button.
Dim oShell, oItem, strSelection, WScript
Set oShell = CreateObject("Shell.Application")
' Invoke Browse For Folder dialog box.
Set oItem = oShell.BrowseForFolder(&H0, title, flag, dir)
strSelection = oItem.title
If Err <> 0 Then 'cancelled
Set oShell = Nothing
Set oItem = Nothing
Exit Function
End If
' If colon found then get drive letter from the title. No array
If InStr(strSelection, ":") Then
BrowseForFolder = Mid(strSelection, InStr(strSelection, ":") - 1, 2)
Else
'Handle all other special cases where path not returned
Select Case strSelection
Case "Desktop"
BrowseForFolder = wshShell.SpecialFolders("Desktop")
Case "My Documents"
BrowseForFolder = wshShell.SpecialFolders("MyDocuments")
Case "My Computer"
MsgBox "Invalid selection", vbCritical + vbOKOnly, "Error"
WScript.Quit
Case "My Network Places"
MsgBox "Invalid selection", vbCritical + vbOKOnly, "Error"
WScript.Quit
Case Else
' Finally try to retrieve the full path a la Born
BrowseForFolder = oItem.ParentFolder.ParseName(oItem.title).Path
End Select
End If
'Cleanup
Set oShell = Nothing
Set oItem = Nothing
'make sure they all end in \
If Right(BrowseForFolder, 1) <> "\" And Len(BrowseForFolder) > 0 Then
BrowseForFolder = BrowseForFolder & "\"
End If
'Alternate make sure they all end without \
' If Right(browseForFolder,1) = "\" Then
' browseforfolder = left(BrowseForFolder,Len(BrowseForFolder)-1)
' End If
On Error GoTo 0
End FunctionMit freundlichen Gr??en,
Andy G. |