VB Script and filename with space

可紊 提交于 2020-01-17 03:34:05

问题


I wrote a VBS file to open the "6 May" folder with following content

path = "F:\Test\2010\May\6 May"
Set Sh = CreateObject("WSCript.Shell")
Sh.Run ""path"",3,True
Set Sh = Nothing 

However on executing this I am getting following error


Windows Script Host

Script: F:\Sperry\2010\May_06 May\open.vbs Line: 4 Char: 10 Error: Expected end of statement Code: 800A0401 Source: Microsoft VBScript compilation error


OK

Can anyone help me in this?


回答1:


Your ""path"" syntax is incorrect. To concatenate strings in VBScript, you need to use the & operator. Also, to specify a quote character as part of the string, you need to double it. So, your script should look like this:

path = "F:\Test\2010\May\6 May"
Set Sh = CreateObject("WSCript.Shell")
Sh.Run """" & path & """", 3, True
Set Sh = Nothing


来源:https://stackoverflow.com/questions/2781995/vb-script-and-filename-with-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!