Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting current directory in VBScript

I'm trying to get the current directory and use it to run an application no matter where the file is put and no matter how the path is changed

Dim fso: set fso = CreateObject("Scripting.FileSystemObject") Dim CurrentDirectory CurrentDirectory = fso.GetAbsolutePathName(".") Dim Directory Directory = CurrentDirectory\attribute.exe  Set WinScriptHost = CreateObject("WScript.Shell") WinScriptHost.Run Chr(34) & "Directory" & Chr(34), 0 Set WinScriptHost = Nothing 

How do I actually set up this code so it does what I want it to do correctly?

like image 241
CodeKeyer Avatar asked Apr 22 '13 03:04

CodeKeyer


People also ask

How do I change the current directory in VBScript?

You can use WScript. ScriptFullName which will return the full path of the executing script. Since OP asked about VBScript, I would like to caution readers on Jakob's first code line, which is an JScript example.

What is WScript echo in VBScript?

You can use WScript. Echo to see exactly what VBScript passes out; if the string you see in the result of WScript. Echo works in a command-prompt window, it will work as the first argument for the Run method.


2 Answers

You can use WScript.ScriptFullName which will return the full path of the executing script.


You can then use string manipulation (jscript example) :

scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1) 


Or get help from FileSystemObject, (vbscript example) :

scriptdir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) 
like image 120
Jakob Sternberg Avatar answered Sep 24 '22 09:09

Jakob Sternberg


You can use CurrentDirectory property.

Dim WshShell, strCurDir Set WshShell = CreateObject("WScript.Shell") strCurDir    = WshShell.CurrentDirectory WshShell.Run strCurDir & "\attribute.exe", 0 Set WshShell = Nothing 
like image 37
Panayot Karabakalov Avatar answered Sep 25 '22 09:09

Panayot Karabakalov