Reputation: 197
I have been trying to find and write a vbscript that enables me to find a filepath and then insert it's location into a text.txt file
For example:
click on Find.vbs
window opens to search for folder or drive
select c:\test folder
are you sure you want to select c:\test folder? prompt
click yes button
in the text.txt file
the word driveselect changes to c:\test
I found this that opens the window and then lets me select a file, it then opens a msgbox to show the file name, but will not select a folder only
Set wShell=CreateObject("WScript.Shell")
Set oExec=wShell.Exec("mshta.exe ""about:<input type=file id=FILE>
<script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""")
sFileSelected = oExec.StdOut.ReadLine
wscript.echo sFileSelected
there are a few codes that i found to change the text in a word file, but not text file with input.
any help would be greatly appreciated.
thanks
Upvotes: 1
Views: 1495
Reputation:
You can use the Excel Application's FileDialog to select a folder.
Dim FolderName, msg, msgResponse
Do
FolderName = getSelectedFolderPath
msg = "Are you sure you want to select " & vbCrLf & FolderName & "?"
msgResponse = MsgBox(msg, vbYesNo,"")
Loop Until Len(FolderName) = 0 Or msgResponse = vbYes
Function getSelectedFolderPath
Const msoFileDialogFolderPicker = 4
Dim xlApp
Set xlApp = CreateObject("Excel.Application")
With xlApp.FileDialog(msoFileDialogFolderPicker)
.Show
If .SelectedItems.Count > 0 Then
getSelectedFolderPath = .SelectedItems(1)
End If
End With
xlApp.Quit
End Function
Upvotes: 1