How do I use the following vbs script to write the output of folderdialog to a file in the same directory as the script instead of the messgae box. Basically I want to write the path given by folderdialog to a text file without echoing to the messagebox

xxgeek 1 Reputation point
2021-07-16T16:16:32.94+00:00

WScript.Echo BrowseFolder( "My Computer", False )
Function BrowseFolder( myStartLocation, blnSimpleDialog )
Const MY_COMPUTER = &H11&
Const WINDOW_HANDLE = 0
Dim numOptions, objFolder, objFolderItem
Dim objPath, objShell, strPath, strPrompt
strPrompt = "Select a folder:"
If blnSimpleDialog = True Then
numOptions = 0
Else
numOptions = &H10&
End If
Set objShell = CreateObject( "Shell.Application" )
If UCase( myStartLocation ) = "MY COMPUTER" Then
Set objFolder = objShell.Namespace( MY_COMPUTER )
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path
Else
strPath = myStartLocation
End If
Set objFolder = objShell.BrowseForFolder( WINDOW_HANDLE, strPrompt, _
numOptions, strPath )
If objFolder Is Nothing Then
BrowseFolder = ""
Exit Function
End If
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
BrowseFolder = objPath
End Function

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,724 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 117.3K Reputation points
    2021-07-16T18:13:25.99+00:00

    Try something like this:

    Dim bf
    bf = BrowseFolder( "My Computer", False )
    
    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
    Dim sp : sp = fso.GetFile(Wscript.ScriptFullName)
    Dim fp: fp = fso.GetParentFolderName(sp) & "\MyFile.txt"
    
    Dim f : Set f = fso.CreateTextFile(fp)
    f.WriteLine bf
    f.Close
    

  2. xxgeek 1 Reputation point
    2021-07-16T20:20:47.897+00:00

    Excellent!!
    Works as needed now.
    Thank you very much for your time, and effort.
    I couldn't have gotten better service if I paid for it.
    You are an exceptional person Viorel-1

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.