Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for brfolder.kix

(view source code of brfolder.kix as plain text)

  1. ? BrowseFolder( "C:\Program Files", True )
  2. ? BrowseFolder( "My Computer", False )
  3. ? BrowseFolder( )
  4.  
  5.  
  6. Function BrowseFolder( Optional $myStartLocation, Optional $blnSimpleDialog )
  7. ; This function generates a Browse Folder dialog
  8. ; and returns the selected folder as a string.
  9. ;
  10. ; Optional Arguments:
  11. ; myStartLocation   [string]  start folder for dialog, or "My Computer",
  12. ;                             or empty to open in "Desktop\My Documents"
  13. ; blnSimpleDialog   [boolean] if False, an additional text field will be
  14. ;                             displayed where the folder can be selected
  15. ;                             by typing the fully qualified path
  16. ;
  17. ; Returns:          [string]  the fully qualified path to the selected folder
  18. ;
  19. ; Based on the Hey Scripting Guys article
  20. ; "How Can I Show Users a Dialog Box That Only Lets Them Select Folders?"
  21. ; http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun05/hey0617.mspx
  22. ;
  23. ; Function written by Rob van der Woude
  24. ; http://www.robvanderwoude.com
  25. 	$MY_COMPUTER   = &11
  26. 	$WINDOW_HANDLE = 0     ; Must ALWAYS be 0
  27.  
  28. 	Dim $numOptions, $objFolder, $objFolderItem
  29. 	Dim $objPath, $objShell, $strPath, $strPrompt
  30.  
  31. 	; Set the options for the dialog window
  32. 	$strPrompt = "Select a folder:"
  33. 	If blnSimpleDialog = False
  34. 		$numOptions = &10  ; Additional text field to type folder path
  35. 	Else
  36. 		$numOptions = 0    ; Simple dialog
  37.  
  38. 	EndIf
  39.  
  40. 	; Create a Windows Shell object
  41. 	$objShell = CreateObject( "Shell.Application" )
  42.  
  43. 	; If specified, convert "My Computer" to a valid
  44. 	; path for the Windows Shell's BrowseFolder method
  45. 	If $myStartLocation = "My Computer"
  46. 		$objFolder = $objShell.Namespace( $MY_COMPUTER )
  47. 		$objFolderItem = $objFolder.Self
  48. 		$strPath = $objFolderItem.Path
  49. 	Else
  50. 		$strPath = $myStartLocation
  51. 	EndIf
  52.  
  53. 	$objFolder = $objShell.BrowseForFolder( $WINDOW_HANDLE, $strPrompt, $numOptions, $strPath )
  54.  
  55. 	; Quit if no folder was selected
  56. 	If $objFolder = Nothing
  57.     	$BrowseFolder = ""
  58.     	Return
  59. 	EndIf
  60.  
  61. 	; Retrieve the path of the selected folder
  62. 	$objFolderItem = $objFolder.Self
  63. 	$objPath = $objFolderItem.Path
  64.  
  65. 	; Return the path of the selected folder
  66. 	$BrowseFolder = $objPath
  67. EndFunction
  68.  

page last uploaded: 2017-08-21, 14:26