' Basic steps…
' #0) Get source directory and destination directory
' #1) Verify Source exists
' #2) Use robocopy to move entire project over to destination
' #3) Use dfscmd to remove old link to project and to create new link
' #4) create a folder on server and create a shortcut to the new link
Set objArgs = WScript.Arguments
if objArgs.Count < 1 Then
' for I = 0 to objArgs.Count - 1
' WScript.Echo I
' WScript.Echo objArgs(I)
' Next
WScript.Echo "Insufficient Parameters"
WScript.Echo "usage:"
WScript.Echo " ArchiveProject.vbs project_directory [/r]"
WScript.Quit(1)
End If
Dim restoreFlag
restoreFlag = false
If objArgs.Count = 2 Then
If objArgs(1) = "/r" Then
restoreFlag = true
End If
End If
Dim FSO ' File System Object
Dim SrcDir
Dim DestDir
Dim WshShell
Dim CmdString
Dim DfsPath
Dim objFolder
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
' #0) Get source directory and destination directory
SrcDir = "\\server1\projects\" & objArgs(0)
DestDir = "\\server2\Oldprojects\" & objArgs(0)
DfsPath = "\\mydomain\dfsroot\projects\" & objArgs(0)
If restoreFlag = true Then
Dim temp
' swap the source and destination directories...
temp = SrcDir
SrcDir = DestDir
DestDir = temp
End If
'WScript.Echo SrcDir
'WScript.Echo DestDir
'WScript.Echo DfsPath
' #1) Verify Source exists
If FSO.FolderExists(SrcDir) Then
WScript.Echo "Folder " & SrcDir & " located. Using Robocopy to move it to " & DestDir & "."
' #2) Use robocopy to move entire project over to Nomad5
CmdString = "robocopy """ & SrcDir & """ """ & DestDir & """ /E /Z /SEC /ETA /MOVE"
WScript.Echo CmdString
ReturnVal = WshShell.Run("cmd /C " & CmdString, 1, True)
WScript.Echo ReturnVal
' #3) Use dfscmd to remove old link to project and to create new link
CmdString = "dfscmd /unmap """ & DfsPath & """ "
WScript.Echo CmdString
ReturnVal = WshShell.Run("cmd /C " & CmdString, 1, True)
CmdString = "dfscmd /map """ & DfsPath & """ """ & DestDir & """ "
WScript.Echo CmdString
ReturnVal = WshShell.Run("cmd /C " & CmdString, 1, True)
' #4) create a folder on source directory and create a shortcut to the new link
Set objFolder = FSO.CreateFolder( SrcDir)
Set oShellLink = WshShell.CreateShortcut(SrcDir & "\Click to go to New Location.lnk")
oShellLink.TargetPath = DestDir
oShellLink.Description = "Shortcut Script to " & DestDir
oShellLink.WorkingDirectory =DestDir
oShellLink.Save
WScript.Echo "Link Created"
Else
WScript.Echo "Source Directory does not exist. Exiting"
WScript.Quit(1)
End If