Moving folders with VBScript

Posted on 2007-08-07
Last Modified: 2013-11-25
I know this is probably real common and easy... however my search over this site and the internet suggests otherwise.  I work in a K-12 environment and we are an 2003 AD environment as well.  Basically I am writing a VBSCript for end of year/start of new year procedures.  The script will move students into their next OU and if they are moving to another building it will move their folder to the new server and adjust their user account properties accordingly.
HOWEVER!  I cannot move the folders!  I literally have spent 2 days trying to figure this out.  I tried using every sample script out there but nothing works!  I just simply need to move folders from a UNC target to a UNC source... can anyone help??  The move folder routines only work on local drives, not network or UNC paths.  

Thanks in advance.  
Question by:mcannet
    LVL 15

    Expert Comment

    why don't you make make your script call a simple batch file?
    LVL 65

    Accepted Solution

    Hi, CopyFolder and MoveFolder do support UNC paths, but you can get into errors with the trailing slashes, this should help overcome those.
    Note that I have used CopyFolder, then DeleteFolder, instead of just MoveFolder, because MoveFolder doesn't support the True flag to overwrite:
    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strSource = "\\d09790ring\c$\temp\movesource\"
    ' This ensures we can use the CopyFolder method, with True to overwrite,
    ' otherwise with the trailing slash, CopyFolder throws an error
    If Right(strSource, 1) = "\" Then strSource = Left(strSource, Len(strSource) - 1)
    strDest = "\\d09790ring\c$\temp\movedest\"
    ' This ensures that the CopyFolder method creates the target folder first, then copies
    ' the source *into* this target folder
    If Right(strDest, 1) <> "\" Then strDest = strDest & "\"
    If objFSO.FolderExists(strDest) = False Then
          objFSO.CreateFolder strDest
    End If
    If objFSO.FolderExists(strSource) Then
          objFSO.CopyFolder strSource, strDest, True
          objFSO.DeleteFolder strSource, True
          MsgBox strSource & " does not exist."
    End If
    Set objFSO = Nothing
    MsgBox "Done"


    LVL 65

    Expert Comment

    Hmmm, that should have been


    LVL 1

    Author Comment

    Rob.. you da man!!  Thank you very much, worked like a champ.
    LVL 65

    Expert Comment

    No problem, thanks for the grade.


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Cobalt Digital Marketing began using the Scrum Framework development process in summer 2009.  We hired a consultant to train the teams, observe meetings, and answer questions. He recommended that we begin using one-week sprints for several reason…
    It was Monday morning and while heading to work those familiar feelings of frustration began to rise: How was I ever going to get my yard work done?! At the end of every weekend I discovered that I spent more time trying to decide what to work on th…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    731 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

    15 Experts available now in Live!

    Get 1:1 Help Now