Saturday, December 15, 2018

VbScript - Get Folder

The snippet of VB script can be used to fetch a folder's name.

' Get Target Folder Path

CONST MY_COMPUTER = &H11 ' Use &H00 to include Desktop
CONST WINDOW_HANDLE = 0  ' Always = 0
CONST OPTIONS = 1        ' Default = 1
CONST BIF_NONEWFOLDERBUTTON = &H200 ' Hide Create New Folder Button

Sub SelectTargetFolder (dummy)

  Set objShell = CreateObject("Shell.Application")
  Set objFolder = objShell.Namespace(MY_COMPUTER)
  Set objFolderItem = objFolder.Self
  strPath = objFolderItem.Path

  ' Start in Folder
  strPath = "C:\temp"

  Set objFolder = objShell.BrowseForFolder _
      (WINDOW_HANDLE, "Select a Target Folder:", OPTIONS, strPath)

  If objFolder Is Nothing Then
      exit sub
  End If

  Set objFolderItem = objFolder.Self
  objSourcePath = objFolderItem.Path

  msgbox "Target Folder: " & objSourcePath,,"Target Folder"

end sub

No comments:

Post a Comment