.BrowseForFolder - VBScript


Overview

The .BrowseForFolder command in VB Script allows users to open a file browser window and select a directory. It is commonly used to obtain user-selected directory paths in scripts or applications.

Syntax

object.BrowseForFolder(Filter, Title, InitialDirectory)

Parameters:

  • object: The object on which the method is being called, typically a FileSystemObject instance.
  • Filter: (Optional) A string specifying the file filter to use when displaying the folder browser. Example: "Folders Only|*.*"
  • Title: (Optional) The title to display for the folder browser window.
  • InitialDirectory: (Optional) The initial directory to show when the folder browser opens.

Options/Flags

None

Examples

Simple Usage:

Dim fso, folder
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.BrowseForFolder()
MsgBox folder

Advanced Usage:

Set folder = fso.BrowseForFolder(Title:="Select Your Pictures Folder", _
               Filter:="Images (*.jpg, *.png, *.bmp)|*.jpg;*.png;*.bmp", _
               InitialDirectory:="C:\My Pictures")

Common Issues

  • Access Denied: Make sure the user has permissions to access the selected folder.
  • Path Too Long: Check if the selected folder path exceeds the maximum path length limit.

Integration

The .BrowseForFolder command can be used with other VB Script commands to automate tasks. For example, it can be combined with the .CopyFolder method to copy files from the selected folder to another location.

  • .CopyFolder
  • .CreateFolder
  • .GetFolder