Excluding a sub directory when using movefolder in VB script

Posted on 2009-02-09
Medium Priority
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
  • 2
LVL 38

Accepted Solution

Shift-3 earned 1000 total points
ID: 23595404
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

ID: 23660458
Thank You

that was perfect.

Author Closing Comment

ID: 31544760
Thank You

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

755 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