使用 VBScript 选择多个文件

问题描述 投票:0回答:2

我在 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
html vbscript jscript hta filesystemobject
2个回答
1
投票

如果这是 HTA,请在 head 标签内添加以下代码:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10"/>

0
投票

这是一个完整的示例,展示了如何提供文件打开对话框来选择多个文本文件:

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
© www.soinside.com 2019 - 2024. All rights reserved.