0

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
    .
Garfield
  • 1,192
  • 3
  • 12
  • 22
  • 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. http://stackoverflow.com/questions/2129327/how-to-get-the-fully-qualified-path-for-a-file-in-vbscript – Sorceri Sep 19 '12 at 22:23

1 Answers1

1
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
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328