| || |
UFT How to get a drive letter where script is opened from
I am trying to get my system Drive letter of where Script.vbs file resides from so that I can use that drive letter to open my Excel datasheet rather than hard-coding drive letter in the script. I tried following code and it always gives me drive letter or C:, because there where UFT is installed.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
strPath = objShell.CurrentDirectory
strDrive = objFSO.GetDriveName(strPath)
I tried to use Relative path but could not get it working..
....\UFTDATASHEET\Dir\Dir1\Dir2\Dir3 <--throws error
You could use them relative to your scripts them use the built-in environment variable "TestDir"
Other than that you can use winmgts to 'find' the file and return it as an object then use object.path. Another way but will be slower is recursively search folders.
There's lots of example of both methods out there.
msgbox Left(fso.GetDriveName(Environment.Value("TestDir") ), 1)
Set fso = Nothing
Originally Posted by VijayChander
Originally Posted by mwsrosso