问题描述
目前我正在用我的 vbscript 打开一个文件,如下所示:
At present I am opening a file with my vbscript as follows:
strFile = "C:Users estfile.txt"
Set objFile = objFSO.OpenTextFile(strFile)
我想改变这一点,以便用户可以选择/导航到一个文件,并在脚本中使用该文件.我怎样才能添加这个能力?我试图搜索如何加载文件对话框/提示用户输入文件等,只是不确定如何在 VBScript 中完成.
I would like to change this so that a file can be selected/navigated to by the user and that file is used in the script. How can I add this ability? I have tried to search for how to load a file dialog/prompt the user for a file etc just not sure how to complete in a VBScript.
推荐答案
我发现另一个有趣的解决方案来自 MS TechNet 更少的定制,但得到你想要实现的目标.这将返回所选文件的完整路径.
There is another solution I found interesting from MS TechNet less customization but gets what you wanted to achieve. This returns the full path of the selected file.
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
这篇关于VBScript 打开一个对话框来选择文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!