我试图通过位于另一个目录中的vbscript编译au3脚本,所以我使用" CurrentDirectory"使用此代码将工作目录从脚本目录更改为au3文件目录的属性
drivepath = "K"
strTempTarget = "New Folder"
filename = "gate.jpg"
IconName = "102.ico"
Comm = "cmd /c " & "Aut2Exe.exe /in " & filename & ".au3" & " /out " & filename & ".exe" & " /icon " & IconName
Path = """" & drivepath & "\" & strTempTarget & """"
MsgBox(Path)
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.CurrentDirectory = Path
objShell.Run(Comm), 0, True
但我收到错误"文件名或目录名无效" 因为" strTempTarget"值我应该在目录名称的开头和结尾加上双引号" Path"我甚至尝试使用ASCII:类似
Path = Chr(34) & drivepath & "\" & strTempTarget & Chr(34)
但同样的错误不断提高 那么如何使这个脚本正常工作呢?
答案 0 :(得分:0)
shell需要引用pathes,因为它使用空格作为分隔符; .CurrentDirectory'知道'整个字符串(包含任何空格)意味着文件夹路径;所以不要引用.CurrentDirectory的字符串。
证据:
>> Set objShell = WScript.CreateObject("WScript.Shell")
>> Path = """C:\Documents and Settings"""
>> objShell.CurrentDirectory = Path
>>
Error Number: -2147024773
Error Description:
>> Path = "C:\Documents and Settings"
>> objShell.CurrentDirectory = Path
>>
>> <-- no news are good news