Folder Name -- Picker

General development discussion.

Moderators: Susan Smith, admin, Gabriel

Post Reply
GomezL
Posts: 258
Joined: Wed Apr 29, 2009 5:51 am
Contact:

Folder Name -- Picker

Post 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?
mikemiller
Posts: 13
Joined: Wed Mar 17, 2021 6:01 am

Re: Folder Name -- Picker

Post 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.
GomezL
Posts: 258
Joined: Wed Apr 29, 2009 5:51 am
Contact:

Re: Folder Name -- Picker

Post 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
mikemiller
Posts: 13
Joined: Wed Mar 17, 2021 6:01 am

Re: Folder Name -- Picker

Post 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!
bluesfannoz
Posts: 291
Joined: Fri Jun 19, 2009 9:01 am
Location: Lawrence, Kansas
Contact:

Re: Folder Name -- Picker

Post 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?
Steve Koger
Computer Specialist
SEKESC-MACS Division
mikemiller
Posts: 13
Joined: Wed Mar 17, 2021 6:01 am

Re: Folder Name -- Picker

Post 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. :D
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.
Post Reply