0
votes

I'm trying to pass the working directory to vbscript as a named argument. The system normally expands "." to the current path, but when I check the named argument I just get the string "."

Here's the command line:

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

Here's the script:

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

Here's the output:

    first arg
    second
    .
1
You will not be able to pass in a dot and expect it to resolve to the full path as the dot comes through as a string. Take a look here as you can get the full path inside your script. stackoverflow.com/questions/2129327/… - Sorceri

1 Answers

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

Or you could use /c:"%CD%" instead of /c:..

If you always want to know the current directory, you don't need to pass it as an argument, though. Simply use

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