Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for getfoldr.vbs

(view source code of getfoldr.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim strPath
  4.  
  5. strPath = SelectFolder( "" )
  6.  
  7. If strPath = vbNull Then
  8. 	WScript.Echo "Cancelled"
  9. Else
  10. 	WScript.Echo "Selected Folder: """ & strPath & """"
  11. End If
  12.  
  13.  
  14. Function SelectFolder( myStartFolder )
  15. ' This function opens a "Select Folder" dialog and will
  16. ' return the fully qualified path of the selected folder
  17. '
  18. ' Argument:
  19. '     myStartFolder    [string]    the root folder where you can start browsing;
  20. '                                  if an empty string is used, browsing starts
  21. '                                  on the local computer
  22. '
  23. ' Returns:
  24. ' A string containing the fully qualified path of the selected folder
  25. '
  26. ' Written by Rob van der Woude
  27. ' http://www.robvanderwoude.com
  28.  
  29. 	' Standard housekeeping
  30. 	Dim objFolder, objItem, objShell
  31.  
  32. 	' Custom error handling
  33. 	On Error Resume Next
  34. 	SelectFolder = vbNull
  35.  
  36. 	' Create a dialog object
  37. 	Set objShell  = CreateObject( "Shell.Application" )
  38. 	Set objFolder = objShell.BrowseForFolder( 0, "Select Folder", 0, myStartFolder )
  39.  
  40. 	' Return the path of the selected folder
  41. 	If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path
  42.  
  43. 	' Standard housekeeping
  44. 	Set objFolder = Nothing
  45. 	Set objshell  = Nothing
  46. 	On Error Goto 0
  47. End Function
  48.  

page last modified: 2024-04-16; loaded in 0.0094 seconds