Path = split(wscript.scriptFullName, wscript.scriptname)(0)
CreateObject("wscript.shell").run(Path & "Name.txt")
如果文件路径和文件名均不包含空格,则上述脚本可以正常工作。
如果其中任何一个包含空格,则结果为;
错误:系统找不到指定的文件。
如何解决该错误?
答案 0 :(得分:2)
规则非常简单:
所有字符串都必须以双引号开头和结尾才能成为有效字符串。
Dim a
a = "Hello World" 'Valid string.
a = "Hello World 'Not valid and will produce an error.
任何对变量的使用都必须使用String Concatenation字符&
来将它们与字符串结合起来。
Dim a: a = "Hello"
Dim b
b = a & " World" 'Valid concatenated string.
b = a " World" 'Not valid and will produce an error.
由于使用双引号定义了字符串,因此必须通过将双引号""
加倍来转义字符串中所有双引号的实例,但规则1仍然适用。
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").run("""" & Path & "Name.txt""")
生成由文字双引号引起来的字符串。
答案 1 :(得分:-3)
CreateObject("wscript.shell").run(""""Path & "Name.txt""")
是这样。