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?
Folder Name -- Picker
Moderators: Susan Smith, admin, Gabriel
-
- Posts: 13
- Joined: Wed Mar 17, 2021 6:01 am
Re: Folder Name -- Picker
I use a .vbs script that I copy client side and call with a batch file.
You can call it with something like this where "FolderPicker.vbs" is the name of the script:
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.
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
Code: Select all
cscript FolderPicker.vbs "C:\Path\to\start\in\" >"C:\Path\to\output_file.txt"
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
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:
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
-
- Posts: 13
- Joined: Wed Mar 17, 2021 6:01 am
Re: Folder Name -- Picker
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!
The main difference I see is my version wasn't cleaning up objShell and the third argument to BrowseForFolder.
Glad I could help!
-
- Posts: 291
- Joined: Fri Jun 19, 2009 9:01 am
- Location: Lawrence, Kansas
- Contact:
Re: Folder Name -- Picker
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?
Steve Koger
Computer Specialist
SEKESC-MACS Division
Computer Specialist
SEKESC-MACS Division
-
- Posts: 13
- Joined: Wed Mar 17, 2021 6:01 am
Re: Folder Name -- Picker
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.
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.