用相对路径vbs打开程序

Bra*_*ney 2 vbscript

我正在尝试从相对于vbs脚本的路径打开x.txt,该脚本位于:“ Help file \ bin \ html \ x.txt”该脚本也位于Help文件文件夹中

dim x, fso, vbpath
Set x = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
vbpath = fso.GetParentFolderName(WScript.ScriptFullName)
otherpath = "\bin\html\x.txt"
msgbox(vbpath & otherpath)
x.Run(vbpath & otherpath)
Run Code Online (Sandbox Code Playgroud)

它找不到路径;路径是msgbox是正确的,但是它仍然找不到路径。我知道它要求“”是x.Run()中的字符串,但直到有变量时,它才不允许我添加它们。

Ekk*_*ner 5

尝试:

vbpath = fso.GetParentFolderName(WScript.ScriptFullName)
' use better name, no leading "\" for .BuildPath
suffix = "bin\html\x.txt"
' use std method
fspec = fso.BuildPath(vbpath, suffix)
' no param lst () when calling a sub
MsgBox fspec
' add quotes
fspec = """" & fspec & """"
' check again
MsgBox fspec
' use checked value, instead of repeating the expression
x.Run fspec
Run Code Online (Sandbox Code Playgroud)