Moving folders with VBScript

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.  
Who is Participating?
RobSampsonConnect With a Mentor Commented:
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"


why don't you make make your script call a simple batch file?
Hmmm, that should have been


mcannetAuthor Commented:
Rob.. you da man!!  Thank you very much, worked like a champ.
No problem, thanks for the grade.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.