Excluding a sub directory when using movefolder in VB script

Posted on 2009-02-09
Last Modified: 2012-05-06
I am trying to write a script to move all of the sub directories in a folder except one subdirectory using the FSO movefolder?
Question by:LDicke
    LVL 38

    Accepted Solution

    Paste the script below into a text file with a .vbs extension.  Customize the value of the strSource variable with the location of the source folder.  Customize the value of the strDest variable with the location of the destination folder.  Customize the value of the strExclude variable with the name of the subfolder to exclude.  Running the script will move all subfolders except the specified one.

    strSource = "c:\source folder"
    strDest = "c:\destination folder"
    strExclude = "excluded folder"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objSource = objFSO.GetFolder(strSource)
    For Each objChild in objSource.Subfolders
        If Not LCase(objChild.Name) = LCase(strExclude) Then
            objFSO.MoveFolder objChild.Path, strDest & "\"
        End If

    Open in new window


    Author Comment

    Thank You

    that was perfect.

    Author Closing Comment

    Thank You

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
    Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
    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…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    734 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

    19 Experts available now in Live!

    Get 1:1 Help Now