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

WScript.Echo BrowseFolder( "My Computer", False )
Function BrowseFolder( myStartLocation, blnSimpleDialog )
Const MY_COMPUTER = &H11&
Dim numOptions, objFolder, objFolderItem
Dim objPath, objShell, strPath, strPrompt
strPrompt = "Select a folder:"
If blnSimpleDialog = True Then
numOptions = 0
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
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

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

2 answers

Sort by: Most helpful
  1. Viorel 103.2K Reputation points

    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

  2. xxgeek 1 Reputation point

    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