Try the codes for yourself to memorize the material. Ask if you have any questions.
So today we are going to talk about the Script Directory. Say we have a file that is located on the desktop, but we don’t know exactly what the directory (address in other words) is. So we are going use a wscript function. We’ve worked with wscript before, examples including wscript.sleep() which tells your VbScript to pause and wscript.quit which quits or exits the script altogether, wscript.echo “” which is the equivalent to a message box.
But for finding the Script Directory, we use wscript.scriptname to tell us the name of the script file and script.scriptfullname gives us the complete path of the script file.
a = wscript.scriptname b = wscript.scriptfullname msgbox a msgbox b
Output:



But if you are looking for only the directory of the script file instead of the full path with the filename, you need to subtract the script-full-name from the script-name using Len, Left, Right functions.
First step is to figure out the number of characters from the script-full-name and from the script-name. Then you subtract them from each other to leave the directory part:
a = Len(wscript.scriptname) b = Len(wscript.scriptfullname) msgbox a msgbox b
Output:


This is how you subtract out the number of characters in the file name from the full path:
c = Len(wscript.scriptfullname)-Len(wscript.scriptname) msgbox c
Output:

Last step:
c = Len(wscript.scriptfullname)-Len(wscript.scriptname) E = Left(wscript.scriptfullname,c) msgbox E
Output:
