Page 1 of 1
Folder Name -- Picker
Posted: Fri Mar 03, 2023 9:02 am
by GomezL
I am looking for a utility that will display a dialog box and then request the user pick a folder.
I know that BR has the "NAME=OPEN:" command, but that is a FILENAME picker, and I only want them to pick the folder.
Does anyone have something that I could use?
Re: Folder Name -- Picker
Posted: Wed May 17, 2023 2:22 pm
by mikemiller
I use a .vbs script that I copy client side and call with a batch file.
Code: Select all
Option Explicit
Dim strPath, objArgs
Set objArgs = WScript.Arguments
strPath = SelectFolder( objArgs(0) )
If strPath = vbNull Then
WScript.Echo ""
Else
WScript.Echo strPath
End If
Function SelectFolder( myStartFolder )
Dim objFolder, objItem, objShell
On Error Resume Next
SelectFolder = vbNull
Set objShell = CreateObject( "Shell.Application" )
Set objFolder = objShell.BrowseForFolder( 0, "Select Folder", &H200, myStartFolder )
If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path
Set objFolder = Nothing
On Error Goto 0
End Function
You can call it with something like this where "FolderPicker.vbs" is the name of the script:
Code: Select all
cscript FolderPicker.vbs "C:\Path\to\start\in\" >"C:\Path\to\output_file.txt"
You can find the docs for BrowseForFolder here.
https://learn.microsoft.com/en-us/windo ... eforfolder
Options documentation for the third argument is here.
https://learn.microsoft.com/en-us/windo ... rowseinfoa
I personally use &H200 to suppress the new folder button.
Re: Folder Name -- Picker
Posted: Wed May 17, 2023 3:03 pm
by GomezL
Nifty!:
I had a problem running the code, I ran your sample through ChatGPT, and it returned the following:
I ran the code using a command like this:
Code: Select all
cscript Folder_Picker.vbs "d:\Rejections\" >d:\work\output_file.txt
Code: Select all
Option Explicit
Dim strPath, objArgs
Set objArgs = WScript.Arguments
strPath = SelectFolder(objArgs(0))
If strPath = vbNull Then
WScript.Echo ""
Else
WScript.Echo strPath
End If
Function SelectFolder(myStartFolder)
Dim objFolder, objShell
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Select Folder", 0, myStartFolder)
If Not objFolder Is Nothing Then
SelectFolder = objFolder.Self.Path
Else
SelectFolder = vbNull
End If
Set objFolder = Nothing
Set objShell = Nothing
End Function
Re: Folder Name -- Picker
Posted: Thu May 18, 2023 5:30 am
by mikemiller
Yep, that should work, too!
The main difference I see is my version wasn't cleaning up objShell and the third argument to BrowseForFolder.
Glad I could help!
Re: Folder Name -- Picker
Posted: Tue Aug 22, 2023 10:45 am
by bluesfannoz
Very cool! Never thought of doing it that way. My first thought is have you run into issues of computers being blocked from running VB scripts?
Re: Folder Name -- Picker
Posted: Mon Aug 28, 2023 7:03 am
by mikemiller
So far, I haven't, surprisingly enough.
At least not with scripts.
I do have the luxury of being an admin in my environment, so if it does happen, I have the ability to whitelist.
Another option would be to digitally sign the script.
In the past I've had problems with executables I've created.
In those circumstances, most modern antivirus vendors have some sort of online facility to submit false positives.
The only problem is that any tweaks will change the hash and force you to resubmit it again.
If you have something you plan on distributing to multiple environments, it's probably best to sign it to avoid that entirely.