How to get the directory that a VBScript is run from

Posted on 2005-04-21
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.
Question by:TASINetwork
    LVL 15

    Assisted Solution


    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


    LVL 28

    Expert Comment

    Or maybe:

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

    Accepted Solution


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

    Author Comment

    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.
    LVL 15

    Expert Comment

    Good stuff glad you got an answer



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    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…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now