Get directory name into variable based on root directory FSO VBScript

Posted on 2009-04-17
Last Modified: 2012-05-06

I have an VBS file I am working on which I need a hand with.  I need to a function which opens a directory and returns the name of a subdirectory within it.  Basically I have a root directory, and inside that directory are 2 things.. The first is a .MDB file, and the second is a subdirectory.  I know the name of the .MDB file each time, but the name of the subdirectory varies.  How can I get the name of the single subdirectory into a variable?  Thanks!
Question by:electricd7
    LVL 67

    Accepted Solution

    Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
    RootDir = "C:\MyFolder\"
    Dim objFolder : Set objFolder = objFSO.GetFolder(RootDir)
    For Each subfolder in objFolder.SubFolders
      msgbox "Subfolder is " & subfolder

    Open in new window


    Author Closing Comment

    Duh!  Thanks again sirbounty!
    LVL 67

    Expert Comment

    Glad I could help! :^)  Thanx for the grade!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (…
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    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

    16 Experts available now in Live!

    Get 1:1 Help Now