[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Moving folders with VBScript

Posted on 2007-08-07
5
Medium Priority
?
4,705 Views
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.  
0
Comment
Question by:mcannet
  • 3
5 Comments
 
LVL 15

Expert Comment

by:vico1
ID: 19650993
why don't you make make your script call a simple batch file?
Vico1
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 19651495
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
Else
      MsgBox strSource & " does not exist."
End If
Set objFSO = Nothing
MsgBox "Done"
'============

Regards.

Rpb/
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19651497
Hmmm, that should have been

"Regards,

Rob."
0
 
LVL 1

Author Comment

by:mcannet
ID: 19653366
Rob.. you da man!!  Thank you very much, worked like a champ.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19658596
No problem, thanks for the grade.

Rob.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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 …
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Integration Management Part 2
Starting up a Project

834 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