Vbscript 如果文件的路径/名称包含空格,则系统无法找到该文件
如果文件路径和文件名都不包含空格,则上述脚本可以正常工作 如果其中一个包含空格,则结果为 错误:系统找不到指定的文件 我如何修复错误Vbscript 如果文件的路径/名称包含空格,则系统无法找到该文件,vbscript,windows-10,Vbscript,Windows 10,如果文件路径和文件名都不包含空格,则上述脚本可以正常工作 如果其中一个包含空格,则结果为 错误:系统找不到指定的文件 我如何修复错误 Path = split(wscript.scriptFullName, wscript.scriptname)(0) CreateObject("wscript.shell").run(Path & "Name.txt") 就是这样。规则相当简单: 所有字符串必须以双引号开头和结尾才能成为有效字符串 CreateObject("wscript.she
Path = split(wscript.scriptFullName, wscript.scriptname)(0)
CreateObject("wscript.shell").run(Path & "Name.txt")
就是这样。规则相当简单:
CreateObject("wscript.shell").run(""""Path & "Name.txt""")
&
将它们与字符串组合
Dim a
a = "Hello World" 'Valid string.
a = "Hello World 'Not valid and will produce an error.
”
,但规则1除外。仍然适用
Dim a: a = "Hello"
Dim b
b = a & " World" 'Valid concatenated string.
b = a " World" 'Not valid and will produce an error.
Dim a: a = "Hello"
Dim b
b = """" & a & " World""" 'Valid escaped string.
b = """ & a & " World""" 'Not valid, start of string is not complete
'after escaping the double quote
'producing an error.
生成由文字双引号包围的字符串
有用的链接
- (有关字符串连接的详细信息)
CreateObject(“wscript.shell”)。运行(“&Path&“Name.txt”)
。您第一次使用的是正确的,但之后没有连接路径
变量。它以前也被回答过很多次,请标记并继续。请在代码中添加一些解释,以便其他人可以从中学习it@Noodles关于这一点,您是对的,但仍然缺少“
和路径之间的和。显然还不够基础。是的,即使从这么简单的台词中也有很多东西值得学习。如果您以前从未使用过这样的行(因为您刚刚开始学习一种新的编程语言),那么绝对有必要查看一些解释。您还可以使用Scripting.FileSystemObject
的BuildPath()
方法来完全避免此问题。IMO,这本可以更好地回答您提出的问题,并将此问题作为副本结束。将其放在这里会混淆dup目标应该是哪个问题的问题。
CreateObject("wscript.shell").run("""" & Path & "Name.txt""")