VBS How to call cmd.exe using a string variable wi

2019-06-06 05:24发布

问题:

I need to call the following:

set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /c copy /y C:\input\" & WScript.Arguments(0) & " C:\output", 0

where the input argument may be "File Name.txt". I have seen countless examples of people doing the same thing using double quotes for a hard coded file location, but nothing using an input argument or variable. What syntax is required so that the command line receives:

copy /y "C:\input\File Name.txt" C:\output

and not

copy /y C:\input\File Name.txt C:\output

for an arbitrary file name?

回答1:

Embed the needed quotes (escaped via doubling) in the surrounding literals:

WshShell.Run "cmd /c copy /y ""C:\input\" & WScript.Arguments(0) & """ C:\output", 0

background, further reading



标签: vbscript cmd