Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine path of current script 3

Status
Not open for further replies.

ddiamond

Programmer
Apr 22, 2005
918
US
I want one vbscript to be able to call another executible that is in the same directory.

I first tried:
WShell.Run ".\Tidy.exe", 2, True

Tidy.exe is in the same directory as my vbscript file.

This only worked if I launched my vbscript from the correct direcory. I then tried:

WShell.Run WScript.Path & "\Tidy.exe", 2, True

Still didn't work. Neither did:

WShell.Run WScript.CurrentDirectory & "\Tidy.exe", 2, True

How can I determine the directory where my vbs file is located? In Visual basic 6.0 it would be app.path.

 
Maybe this will help you along...


Code:
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
WScript.Echo objFSO.GetParentFolderName(WScript.ScriptFullName)
WScript.Echo WScript.ScriptFullName

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
strCurrentFolder = UCase(Left(Wscript.ScriptFullName, Len(Wscript.ScriptFullName) - Len(Wscript.ScriptName) - 1))
 
[1]
>WShell.Run WScript.CurrentDirectory & "\Tidy.exe", 2, True

First that there is no such thing as wscript.CurrentDirectory, it is WShell.CurrentDirectory!
[tt]
WShell.Run [red]WShell[/red].CurrentDirectory & "\Tidy.exe", 2, True[/tt]

[2] Second, one little trick I sometimes use is this.
[tt]
spath=replace(wscript.scriptfullname,wscript.scriptname,"")
[/tt]
spath would have a trailing backslash. If it happens to be the same as WShell.currentDirectory, they differ only by the trailing backslash: former have it, latter have it not.
 
Talk about choice huh...


--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Thanks dm4ever and mrmovie. Both of your examples did exactly what I wanted.
 
tsuji,

I just saw your reply. Your trick also works. As dm4ever put it, I have a lot of choices.

- Dan
 
[3]
How can I determine the directory where my vbs file is located? In Visual basic 6.0 it would be app.path.

Just to help clear up some basic, if the launching happens to be this. (The case of double-click on script.vbs would be trivial.)

[tt] d:\x\y>c:\windows\system32\cscript.exe f:\z\script.vbs
[/tt]
[ul][li][tt] currentdirectory: d:\x\y[/tt][/li]
[li][tt] spath : f:\z\[/tt][/li][/ul]
 
Thanks tsuji for clearing that up. I also observed that in your example above, WScript.Path will return c:\windows\system32.

Thanks everyone for your quick replies.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top