Since my post on VBScript command line parameters is by far the most popular, here’s some useful script we use to get the current directory your script is running from. This is great for referencing other files.
currentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
Pretty simple one to follow, it grabs the script name (with path), finds the length, grabs the script name by itself, finds the length, subtracts and you’re left with the path. Too easy, but really useful.
Edit: This post has been very popular and there have been a few alternatives provided, here are some of them:
- Set oShell = CreateObject(”WScript.Shell”)
Set ofso = CreateObject(”Scripting.FileSystemObject”)
oShell.CurrentDirectory = oFSO.GetParentFolderName(Wscript.ScriptFullName)
- set wshell = createobject(”wscript.shell”)
‘This gives the current shell directory rather than the script’s directory – use with caution!
Please test whichever you use!