- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个小的 hta 文件,其中包含一些 vbs 代码。它选择文件夹或文件,然后将其复制到固定位置。
<html>
<head>
<Title>File Copy </Title>
<style>
img.exco
{
position:absolute;
bottom:10px;
right:10px
}
</style>
<!--Put this sub here to avoid resize flickering.-->
<script language = "VBScript">
sub DoResize
'resize
window.resizeTo 690,350
screenWidth = Document.ParentWindow.Screen.AvailWidth
screenHeight = Document.ParentWindow.Screen.AvailHeight
posLeft = (screenWidth - 700) / 2
posTop = (screenHeight - 430) / 2
'move to centerscreen
window.moveTo posLeft, posTop
end sub
DoResize()
</script>
<HTA:APPLICATION ID=""
applicationName=""
version="1.1"
BORDER="thin"
BORDERSTYLE="static"
CAPTION="Yes"
CONTEXTMENU="no"
ICON="C:\icon\32x32.ico"
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
NAVIGATABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
>
<script language = "VBScript">
Sub BrowseSource_OnClick()
strStartDir = "K:\Data\"
Copy_To_PC.txtFile.value = PickFolder(strStartDir)
End Sub
Function PickFolder(strStartDir)
Dim shell : Set shell = CreateObject("Shell.Application")
Dim file : Set file = shell.BrowseForFolder(0, "Choose a file:", &H4000)
If (Not File Is Nothing) Then
PickFolder = file.self.Path
End If
Set shell = Nothing
Set file = Nothing
End Function
Sub RunScripts_OnClick()
Copy
Paste
OpenWord
End Sub
Sub Copy
End Sub
Sub Paste
msgBox "Copy Success!"
End Sub
Sub OpenWord
End Sub
</script>
</head>
<body>
<p><b><font size="4">Please select the file.</font></b></p>
<form name="Copy_To_PC">
<input type = "text" name = "txtFile" size="100" />
<input type = "button" value = "File Source" Name="BrowseSource">
<input type="button" value="Copy and Paste" name="RunScripts">
</form>
</body>
</html>
当我单击第一个按钮时,我在选择项目(文件夹或文件)时遇到问题。
它可以很好地拾取文件夹,但是在选择文件时,我收到“第 60 行未指定的错误”,请帮助我排除故障。我希望文件浏览器窗口像现在一样带有“确定”按钮,而不是“打开”按钮,这样我就可以选择文件夹或文件。
文件浏览器也不会从我设置的位置启动。如何解决?
最佳答案
如何在同一窗口中选择文件夹或文件?通过MSDN , Shell.BrowseForFolder
方法创建一个对话框,使用户能够选择一个文件夹,然后返回所选文件夹的 Folder
目的。
因此,为了浏览文件,我们需要使用另一种方法。存在原生<input ...>
标记为 type="file"
属性。然而,使用它弊大于利(参见下面的第二个解决方案)。
在下一个解决方案中,浏览文件是通过使用 HtmlDlgHelper
实现的object - 一个晦涩且记录很少的对象,但在所有 Windows 系统上都可用...与 <input ...>
相比如上所述,该解决方案提供了定义初始位置和文件类型屏蔽的功能。
<HTML>
<HEAD>
<Title>File/Folder Copy B</Title>
<!-- Browse for
- file: based on the HTMLDlgHelper class
registered via C:\Windows\System32\mshtmled.dll
(.OpenFileDlg returns string)
- folder: based on the Shell.BrowseForFolder method
(returns the selected folder's Folder object)
-->
<HTA:APPLICATION
ID=""
APPLICATIONNAME="28632270ym"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<script language="VBScript">
''''''''''''''''''''''''''
''' Global State Variables
''''''''''''''''''''''''''
Dim sStartPath, sStartFile, sFilter, sCaption
sStartPath = "D:\Remote"
sStartFile = sStartPath & "\nul"
sFilter = "All Files (*.*)|*.*|" _
& "VBScript (*.vbs;*.vbc)|*.vbs;*.vbc|" _
& "HTML (*.htm;*.html;*.hta)|*.htm;*.html;*.hta|"
sCaption = "Choose a File:"
Sub Window_Onload
self.Focus()
self.moveTo 1, 1
self.ResizeTo 760,400
End Sub
Sub BrForFolder
sBFF = PickFolder(sStartPath)
If not sBFF = "" Then
document.Copy_To_PC.txtfile.value = sBFF
document.Copy_To_PC.OKbuton.value = "Treat folder"
End If
End Sub
Sub BrForFile_onclick
sBFF = Dlg.OpenFileDlg( CStr(sStartFile), , CStr(sFilter), CStr(sCaption))
If not sBFF = "" Then
document.Copy_To_PC.txtfile.value = sBFF
document.Copy_To_PC.OKbuton.value = "Treat file"
End If
End Sub
Function PickFolder(sStartPath)
Dim shell, oFldr
Set shell = CreateObject("Shell.Application")
Set oFldr = shell.BrowseForFolder(0, "Choose a folder:" _
, &H0001 + &H0004 + &H0010 + &H0020, sStartPath)
'See MSDN "BROWSEINFO structure" for constants
If (Not oFldr Is Nothing) Then
PickFolder = oFldr.Self.Path
Else
PickFolder = ""
End If
Set shell = Nothing
Set oFldr = Nothing
End Function
Sub DoFileOK()
MsgBox document.Copy_To_PC.OKbuton.value _
& " """ & document.Copy_To_PC.txtfile.value & """"
document.Copy_To_PC.txtfile.value = ""
document.Copy_To_PC.OKbuton.value = "Undefined"
End Sub
</script>
</HEAD><BODY>
<OBJECT id=Dlg classid="CLSID:3050F4E1-98B5-11CF-BB82-00AA00BDCE0B"
width=0 height=0>
</OBJECT>
<FORM name="Copy_To_PC">
<p><b><font size="3">Please select a file or folder.</font></b></p>
<input style="width:600px;" type="text" id="txtfile" name="txtfile" />
<br>
<input type="button" value="Browse for File..." id="BrForFile">
or
<input type="button" value="Browse for Folder..." onClick=BrForFolder()>
<br>
<br>Action
<input type="button" value="Undefined" id="OKbuton" onClick=DoFileOK()>
<br>
<br>Quit:
<input type="button" value="All done" onClick=self.window.close()>
</FORM></BODY></HTML>
第二个解决方案:
<html>
<head>
<Title>File/Folder Copy A</Title>
<!-- based on <input type="file"> of zero width -->
<HTA:APPLICATION
ID=""
APPLICATIONNAME="28632270my"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<script language = "VBScript">
''''''''''''''''''''''''''
''' Global State Variables
''''''''''''''''''''''''''
sStartPath = "D:\Remote"
sFilter = "application/pdf,text/plain"
Sub Window_Onload
self.Focus()
self.moveTo 1, 1
self.ResizeTo 960,400
End Sub
Sub BrForFolder()
sBFF = PickFolder(sStartPath)
If sBFF = "" Then
'do not overwrite .txtfile.value with an empty string
Else
Copy_To_PC.txtfile.value = sBFF
Copy_To_PC.OKbuton.value = "Treat folder"
End If
'NOT possible (security reason): Copy_To_PC.fn_file.value = ""
End Sub
Sub BrForFile()
'??? how to know whether a user has pressed 'Open' or 'Cancel' ???
'http://stackoverflow.com/a/4628563/3439404
'The result of the file dialog is not exposed to the browser.
'
'??? how to set initial working directory???
' and file types??? (MSIE does not care about the accept attribute?)
sBFF = Copy_To_PC.fn_file.value
If sBFF = "" Then
'do not overwrite .txtfile.value with an empty string
Else
Copy_To_PC.txtfile.value = sBFF
Copy_To_PC.OKbuton.value = "Treat file"
End If
End Sub
Function PickFolder(sStartPath)
Dim shell : Set shell = CreateObject("Shell.Application")
Dim oFldr : Set oFldr = shell.BrowseForFolder(0, "Choose a folder:" _
, &H0001 + &H0004 + &H0010 + &H0020, sStartPath)
'See MSDN "BROWSEINFO structure" for constants
'Shell.BrowseForFolder method: Creates a dialog box that
' enables the user to select a folder and then returns
' the selected folder's Folder object.
If (Not oFldr Is Nothing) Then
PickFolder = oFldr.Self.Path
Else
PickFolder = ""
End If
Set shell = Nothing
Set oFldr = Nothing
End Function
Sub DoFileOK()
MsgBox Copy_To_PC.OKbuton.value _
& " """ & Copy_To_PC.txtfile.value & """"
Copy_To_PC.txtfile.value = ""
Copy_To_PC.OKbuton.value = "Undefined"
End Sub
</script>
</head><body><form name="Copy_To_PC">
<p><b><font size="3">Please select a file or folder.</font></b></p>
<input style="width:600px;" type="text" id="txtfile" name="txtfile" />
<input style="width:0px;" type="file" id="fn_file" name="fn_file"
accept=sFilter onChange=BrForFile() onBlur=BrForFile()>
or
<input type="button" value="...for Folder..." onClick=BrForFolder()>
<br>
<br>Action
<input type="button" value="Undefined" id="OKbuton" onClick=DoFileOK()>
<br>
<br>Quit:
<input type="button" value="All done" onClick=self.window.close()>
</form></body></html>
关于VBScript 文件或文件夹选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28632270/
我正在使用下面的脚本来调用另一个脚本。问题是我必须将 WScript.Arguments 检索到的参数传递给我正在调用的第二个脚本。有人可以告诉我该怎么做吗。 Dim objShell Set obj
我正在使用下面的脚本来调用另一个脚本。问题是我必须将我通过 WScript.Arguments 检索的参数传递给我正在调用的第二个脚本。有人可以告诉我该怎么做吗。 Dim objShell Set o
我有一个非常简单的 vbscript 代码: Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Prog
我需要将名称基于日期的文件移动到另一个文件夹。 文件结构为: 来源: \\network_location\folder\Filename_09-11-2012.txt 目的地: C:\Dump\Fi
我有一个关于 VBScript 中变量作用域的问题。我知道有以下关键字(来自 autoitscript.com ): Dim = 局部作用域,如果变量名在全局不存在(在这种情况下它重用全局变量!) G
我正在尝试在 VBScript 中运行以下代码但它没有编译最后一条语句。是不是因为VBScript不允许命名参数? Filename_Argument = WScript.Arguments(0) S
在VBScript中,我需要确保用户输入一个整数。 这是我现在所拥有的: WScript.Echo "Enter an integer number : " Number = WScript.StdI
使用这些信息,我学会了here和here。 我在下面创建了短代码。 当我运行代码并有意识地输入任务计划程序库的“\”文件夹中存在的任务时,我收到“任务不存在” msgbox。 我尝试在传递给函数的变量
我试图仅用VBScript编写一个小的脚本供家庭使用,该脚本在Macrium Reflect中进行预定备份之前运行。 我被困在一个看似很小的问题上,这是在物理断开网络驱动器(即未连接电缆)时的错误处理
我阅读了 Eric Lippert 关于 VBScript 中默认属性语义的文章:http://blogs.msdn.com/b/ericlippert/archive/2005/08/30/4580
我正在尝试使用 VBScript 过滤二维数组,但 VBScript 的内置“过滤器”函数仅适用于单维数组。我使用的是“rs.GetRows()”数组,那么是否有一个可以处理二维数组的简单函数? 编辑
尝试在 HP-UFT 中运行时,下面的 VBScript 代码让我感到困惑,因为第一个语句打印 True 而不是 False (这似乎不合逻辑),而第二个打印 False (这似乎合乎逻辑) 代码:
我刚刚了解到 $ 需要转义字符。 VBScript 中还有哪些特殊字符? 还有一个 bool 函数可以用来判断一个字符是否是特殊字符? 最佳答案 嗯? WScript.Echo "$" 输出 $ 而不
我需要将批处理文件转换为 vbscript,但我对两者都不熟悉。如果我能理解批处理文件中发生的事情,我就可以很容易地计算出 vbscript。问题是批处理文件运行一些 cscript 命令,其语法应该
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
长期以来,人们一直在批处理文件中嵌入和执行 VBScript。但是我看到的所有已发布的解决方案(在最初提出这个问题时)都涉及编写临时 VBS 文件。例如:Embed VBScript inside W
如何检查文件夹中是否存在任意名称的文件?我还想忽略子文件夹。 谢谢。 编辑: 我想我已经明白了,但也感谢任何贡献...... If Folder.Files.Count > 0 Then 'Do
我对编程很陌生,我想制作一个程序,从 Vb 脚本的列表中随机选择一个名称或句子。 这是列表: Jacob James Jason Caleb Ashlee John 程序需要从该列表中选择一个随机名称
如何检查文件夹中是否存在任意名称的文件?我还想忽略子文件夹。 谢谢。 编辑: 我想我已经明白了,但也感谢任何贡献...... If Folder.Files.Count > 0 Then 'Do
我需要一个 Vbscript,它可以从我的 PC 打开一个图像文件,并在几分钟后自动关闭。我计划通过命令提示符运行脚本,非常感谢任何帮助。 最佳答案 使用 HTML Application 可能更容易
我是一名优秀的程序员,十分优秀!