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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determine current directory that a script is executing from

Status
Not open for further replies.

sumgirl

IS-IT--Management
Mar 19, 2003
55
US
Hi all. I have a script thats going to connect to a remote machine and copy files back to the local (executing) machine. Problem is, I need to get the scripts copied back to whatever directory the script is running in (it will be distributed to folks and thay can put it where they want it) and so need to determine that relative location so I can pass it in as the copy to path.

Can someone help?
 
Here is one that gives the calling folder, program line and the name of the program.

David


'********************************************************************************************
'This function returns the path from which the script was called
'Call ScriptPath(strFolder,strCommand,strProgramName)
'wscript.echo "Called from folder : -> " & strFolder
'wscript.echo "Calling Program Line : -> " & strCommand
'wscript.echo "Calling Program Name : -> " & strProgramName
'wscript.quit

Function ScriptPath(callingfolder, callingcommandline, callingprogramname)
ScriptPath=Left(Wscript.scriptfullname,Instr(1,WScript.ScriptFullName,wscript.scriptname,1)-1)
callingfolder=scriptpath
callingcommandline=wscript.scriptfullname
callingprogramname=left(wscript.scriptname,len(wscript.scriptname)-4)
End Function
'********************************************************************************************
 
Hello davidnix,

Further to what conan3's posted which is fine and may well be what you need, this is the notion of currentdirectory determined like this in a condensed form.
[tt]s=createobject("wscript.shell").currentdirectory[/tt]
This difference is best illustrated with command prompt.
[tt]
[blue]d:\test>[/blue]wscript c:\script\yourscript.vbs [green][hard enter][/green]
[/tt]
Then what conan3's approach result in showing:
[tt]c:\script[/tt]
whereas the currentdirectory is giving:
[tt]d:\test[/tt]
(modulo trailing backslash if any)
If the script is executed by double-click in the explorer gui, both result the same.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top