[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to get the directory that a VBScript is run from

Posted on 2005-04-21
5
Medium Priority
?
188 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:TASINetwork
  • 2
  • 2
5 Comments
 
LVL 15

Assisted Solution

by:Colosseo
Colosseo earned 1000 total points
ID: 13832834
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
 
LVL 28

Expert Comment

by:vinnyd79
ID: 13832902
Or maybe:

Dim FSO, Fldr
Set FSO = CreateObject("scripting.filesystemobject")
Set Fldr = FSO.GetFolder("./")
MsgBox Fldr.Path
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 1000 total points
ID: 13832932
or

Dim FSO,Fldr
Set FSO = CreateObject("scripting.filesystemobject")
MsgBox FSO.getparentfoldername(Wscript.scriptfullname)
0
 
LVL 2

Author Comment

by:TASINetwork
ID: 13833696
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
 
LVL 15

Expert Comment

by:Colosseo
ID: 13833776
Good stuff glad you got an answer

Cheers

Scott
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month20 days, 13 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question