我在 Windows 7/10 中使用以下脚本打开文件对话框并允许用户选择文件。即使添加了多个属性,它也不允许我选择多个文件。根据 this,我应该能够使用
<input type="file">
的 multiple 属性来选择多个文件。
Set wShell = CreateObject("WScript.Shell")
Set oExec = wShell.Exec("mshta.exe ""about:<input type=file id=FILE name=file multiple><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""")
sFileSelected = oExec.StdOut.ReadLine
WScript.Echo sFileSelected
如果这是 HTA,请在 head 标签内添加以下代码:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10"/>
这是一个完整的示例,展示了如何提供文件打开对话框来选择多个文本文件:
Function BrowseForFileWithFilter(f):BrowseForFileWithFilter=CreateObject("WScript.Shell").Exec("mshta.exe ""about:<meta http-equiv=""X-UA-Compatible"" content=""IE=11""><input type=file id=f multiple accept="""&f&"""><script>resizeTo(0,0);f.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(f.value);close();</script>""").StdOut.ReadLine():End Function
SelectedFile = BrowseForFileWithFilter(".txt")
MsgBox SelectedFile