Rob van der Woude's Scripting Pages

VBScript Scripting Techniques > User Interaction > Select Folder Dialog

Select Folder Dialog


VBScript Code:
Option Explicit

Dim strPath

strPath = SelectFolder( "" )
If strPath = vbNull Then
    WScript.Echo "Cancelled"
    WScript.Echo "Selected Folder: """ & strPath & """"
End If

Function SelectFolder( myStartFolder )
' This function opens a "Select Folder" dialog and will
' return the fully qualified path of the selected folder
' Argument:
'     myStartFolder    [string]    the root folder where you can start browsing;
'                                  if an empty string is used, browsing starts
'                                  on the local computer
' Returns:
' A string containing the fully qualified path of the selected folder
' Written by Rob van der Woude

    ' Standard housekeeping
    Dim objFolder, objItem, objShell
    ' Custom error handling
    On Error Resume Next
    SelectFolder = vbNull

    ' Create a dialog object
    Set objShell  = CreateObject( "Shell.Application" )
    Set objFolder = objShell.BrowseForFolder( 0, "Select Folder", 0, myStartFolder )

    ' Return the path of the selected folder
    If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path

    ' Standard housekeeping
    Set objFolder = Nothing
    Set objshell  = Nothing
    On Error Goto 0
End Function
Windows version: any
Network: N/A
Client software: N/A
Script Engine: WSH
Summarized: Works in any Windows version.
Select Folder dialog (Shell.Application)
[Back to the top of this page]

page last modified: 2016-09-19; loaded in 0.0071 seconds