vbscript将当前目录作为命名参数传递

时间:2012-09-19 21:43:46

标签: command-line vbscript command-line-arguments wsh

我正在尝试将工作目录作为命名参数传递给vbscript。系统通常会扩展“。”到当前路径,但是当我检查命名参数时,我只得到字符串“。”

这是命令行:

    cscript myscript.vbs /a:"first arg" /b:second /c:.

这是脚本:

    dim args : set args = wscript.arguments.named
    wscript.echo args.item("a")
    wscript.echo args.item("b")
    wscript.echo args.item("c")

这是输出:

    first arg
    second
    .

1 个答案:

答案 0 :(得分:1)

Set fso = CreateObject("Scripting.FileSystemObject")
WScript.Echo fso.GetAbsolutePathName(args("c"))

或者您可以使用/c:"%CD%"代替/c:.

如果您总是想知道当前目录,则不需要将其作为参数传递。只需使用

cwd = CreateObject("WScript.Shell").CurrentDirectory