VBS - Relative Path

J-Will

[H]ard|Gawd
Joined
Jan 10, 2009
Messages
1,728
I am creating a website with the purpose of making copies on removable media such as CDs and thumb drives. I would like to use IE in -k mode to open the home page.

This VBS achieves this:
Code:
Set WshShell = WScript.CreateObject("WScript.Shell") 
Return = WshShell.Run("iexplore.exe -k www.google.com", 1)

Replacing 'www.google.com' with the full path of my html file works. However, since I will not know the full path of the file being that it will be on some sort of removable media, I cannot use a specific path.

My question is how do I use a relative path in VBS? The idea is to have the script at the root of the media, with a folder for the 'website'. So I'd just need the path to the containing folder of the script, and append \website\index.html to the VAR and throw that in the code. But how?
 
Server.MapPath, maybe?
Posted via Mobile Device
 
no, anything I put in the double quotes is explicitly used as te URL. I am unable to concatinate the lines properly I suppose.
 
Try this:

Code:
Set WshShell = WScript.CreateObject("WScript.Shell") 
currentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
Return = WshShell.Run("iexplore.exe -k file://" & currentDirectory & "website\index.html", 1)

H.
 
Try this:

Code:
Set WshShell = WScript.CreateObject("WScript.Shell") 
currentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
Return = WshShell.Run("iexplore.exe -k file://" & currentDirectory & "website\index.html", 1)

H.

That did work, and performed exactly what I needed it too. Thank you

Can you explain what the middle line does, for my understanding? I am new to scripting in VBS. I fully understand the first and second lines
 
Can you explain what the middle line does, for my understanding? I am new to scripting in VBS. I fully understand the first and second lines
If you understand the first two, then the only detail you'd be uncertain of is a string concatenation that dynamically builds a path to the file from the currentDirectory + the hard-coded "website" and file.
 
If you understand the first two, then the only detail you'd be uncertain of is a string concatenation that dynamically builds a path to the file from the currentDirectory + the hard-coded "website" and file.

exactly, I get that the second line does something and stores it as a variable. I was just hopeing for a breakdown of what exactly those method calls do. And then the 3rd line calls that var.
 
Last edited:
exactly, I get that the second line does something and stores it as a variable. I was just hopeing for a breakdown of what exactly those methos calls do.
Ah, so you didn't understand the second line. Left() is a string parsing function that returns a string up to a particular index. That "currentDirectory" variable stores the result of the Left() function, which takes the entire path to the current file, and only grabs up to the last "\" character. So "currentDirectory" only has the folder path.
 
Thank you, again, this script is just what I needed. I basically just made a GUI out of HTML/ javascript, and we want to be able to distribute this however. I just wanted a simple way to run the program without making it 100% obvious to the end user that it is just a website (even though it is not a secret). This simple script gives us a single point of launching the site.
 
No problem - glad it helped.

PTNL pretty much covered what the line does - but

We take the left most X characters of the fullname of the script - which will be something like F:\myscript.vbs, where X is the length of the scriptfullname ( F:\myscript.vbs ) less the length of just the scriptname ( myscript.vbs). The left most characters then will be "F:\". Then in the IE call we append your website directory and the index file.

H.
 
Back
Top