Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Relative Path

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2103
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Relative Path
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Relative Path - 2/18/2005 1:47:12 AM   
  Bushmen

 

Posts: 122
Score: 0
Joined: 2/4/2005
From:
Status: offline
Hi,

Does anyone know how what to use for relative paths in vbs.

in vb, ".\" always points to the relative path of anything, i.e. a file

how about vbs?

for instance: say i am running a file.vbs in

MainFolder
SubFolder1 - file.vbs
SubFolder2 - kill.exe

say i want to call kill.exe within file.vbs, but i don't know where the actual
MainFolder is located.. could be on a network, or locally.

i want to be able to work out where is subfolder1 (maybe getparent??)
then get subfolder2 and call kill.exe..

regards,

ben

_____________________________

Scripting is Fab!!
 
 
Post #: 1
 
 Re: Relative Path - 2/18/2005 2:23:19 AM   
  CaffeineAddiction

 

Posts: 144
Score: 0
Joined: 2/9/2005
From:
Status: offline
Just put the name of the file ... this shoud get you the file in the same folder that the script is in ... as far as get parent ... dont know if that is possible with vbscript

(in reply to Bushmen)
 
 
Post #: 2
 
 Re: Relative Path - 2/18/2005 4:00:25 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
If you know that kill.exe is stored on the same level as file.vbs in the filesystem hierarchy, it works the same as any PC environment.

shell.run "%COMSPEC% /C ..\SubFolder2\kill.exe"

Was that really what you asked though ?

(in reply to Bushmen)
 
 
Post #: 3
 
 Re: Relative Path - 2/18/2005 5:11:53 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
You can use WScript.ScriptFullName to get the path and name of the script. With that you can then use get the parent folder of the script.

(in reply to Bushmen)
 
 
Post #: 4
 
 Re: Relative Path - 2/20/2005 6:06:09 AM   
  Bushmen

 

Posts: 122
Score: 0
Joined: 2/4/2005
From:
Status: offline
hmm

"WScript.ScriptFullName"..

is that the full path for the current script that is busy executing?

If so, then I see what you mean regarding using that, going one "\" back and then calling kill.exe in subfolder2 as per token's post.

Ok, say that is the case, am i right in saying the "InstrRev" function could be used to
manipulate the Wscript.ScriptFullName "path"??

Regards,
Bushmen

(in reply to Bushmen)
 
 
Post #: 5
 
 Re: Relative Path - 2/20/2005 7:49:46 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
You could just use the following,

WScript.Echo fso.GetParentFolderName(WScript.ScriptFullName) to get the parent folder to which the script resides. To do exactly what you want, you could use the following,

WScript.Echo fso.BuildPath(fso.GetParentFolderName(fso.GetParentFolderName(WScript.ScriptFullName)), "subfolder2\kill.exe")

(in reply to Bushmen)
 
 
Post #: 6
 
 Re: Relative Path - 2/21/2005 5:08:52 AM   
  netmarcos

 

Posts: 55
Score: 0
Joined: 12/7/2004
From: USA
Status: offline
I often use this to get the path to the folder of the current file:

Set objFSO = CreateObject("Scripting.FileSystemObject")
strFilePath = objFSO.GetAbsolutePathName(".")

(in reply to Bushmen)
 
 
Post #: 7
 
 Re: Relative Path - 2/21/2005 5:47:43 AM   
  Bushmen

 

Posts: 122
Score: 0
Joined: 2/4/2005
From:
Status: offline
thanks for your input everyone..

I've used a mixture of Token's and Netmacro's code.

This now works perfectly..

Relative Path wise, this from Netmacro was what i was looking for:

Set objFSO = CreateObject("Scripting.FileSystemObject")
strFilePath = objFSO.GetAbsolutePathName(".")

Then, to get the rest, Token's code came in handy..

Geez.. only been posting a few weeks, and already I can feel my scripting is coming along nicely..

Regards,
Bushmen

(in reply to Bushmen)
 
 
Post #: 8
 
 Re: Relative Path - 2/21/2005 3:52:11 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
heh.. welcome to the club :)

(in reply to Bushmen)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Relative Path Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts