How to get the directory that a VBScript is run from

I need my vbscript to check for files that are in the same directory as itself (path will be changing due to running it on different PCs at different companies), but the problem is, when I just list a filename it checks the system32 directory.
LVL 2
TASINetworkAsked:
Who is Participating?
 
vinnyd79Connect With a Mentor Commented:
or

Dim FSO,Fldr
Set FSO = CreateObject("scripting.filesystemobject")
MsgBox FSO.getparentfoldername(Wscript.scriptfullname)
0
 
ColosseoConnect With a Mentor Commented:
Hi

You could use this

strFolder = Left(wscript.ScriptFullName,inStrRev(wscript.ScriptFullName,"\")-1)

wscript.ScriptFullName returns the full path and filename

the above line removes the file name so if your file was

c:\test\testscript.vbs you would get c:\test

HTH

Scott
0
 
vinnyd79Commented:
Or maybe:

Dim FSO, Fldr
Set FSO = CreateObject("scripting.filesystemobject")
Set Fldr = FSO.GetFolder("./")
MsgBox Fldr.Path
0
 
TASINetworkAuthor Commented:
Thanks for the fast response!  Both accepted answers work well (I chose vinnyd79's as I've been using FSO throught my script - if it wasn't for that I would have used Colosseo's as you don't need to create any objects.

Vinnyd79: Your first response pulled up my profile path rather than the script path.
0
 
ColosseoCommented:
Good stuff glad you got an answer

Cheers

Scott
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.